91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

如何殺掉一個用戶下的所有進程并drop掉這個用戶

發布時間:2020-08-09 07:13:09 來源:ITPUB博客 閱讀:244 作者:dbasdk 欄目:關系型數據庫
如何殺掉一個用戶下的所有進程并drop掉這個用戶


Copy the sample code below into a file named kill_drop_user.sql.
Open SQL*Plus and connect as user SYS to your database
SQL> CONNECT sys/change_on_install@orcl AS SYSDBA
Create a user called TEST with password TEST
SQL> GRANT connect, resource TO test IDENTIFIED BY test;
Create the procedure kill_drop_user
SQL> @"C:\scripts\kill_drop_user.sql"
Open three (3) SQL*Plus sessions and connect as user TEST.
Execute the PL/SQL script
SQL> SET serveroutput ON size 1000000 SQL> SET timing ON SQL> EXEC kill_drop_user('TEST');
CAUTION


This sample code is provided for educational purposes only, and is not supported by Oracle Support. It has been tested internally, however, we do not guarantee that it will work for you. Ensure that you run it in your test environment before using.
SAMPLE CODE


CREATE OR REPLACE PROCEDURE kill_drop_user (in_username IN VARCHAR2,
                                            sleep_interval IN NUMBER DEFAULT 10)
AS
  PRAGMA AUTONOMOUS_TRANSACTION;


  cannot_drop_user EXCEPTION;
  PRAGMA EXCEPTION_INIT(cannot_drop_user, -1940);


  user_count    NUMBER := -1;


BEGIN


  SELECT count(*) INTO user_count FROM dba_users WHERE username = in_username;
  IF user_count = 0 THEN
    DBMS_OUTPUT.PUT_LINE('User ' || in_username || ' does not exist.');
    RETURN;
  END IF;


  FOR i IN (SELECT sid, serial# FROM v$session WHERE username = in_username) LOOP
    EXECUTE IMMEDIATE 'alter system kill session ' || '''' || i.sid || ',' || i.serial# || ''' immediate';
    DBMS_OUTPUT.PUT_LINE('Killing user ' || i.sid || ', ' || i.serial#);
  END LOOP;


  LOOP
    BEGIN
      DBMS_OUTPUT.PUT_LINE('Attempting to drop user ' || in_username || '...');
      EXECUTE IMMEDIATE 'DROP USER ' || in_username || ' CASCADE';


      EXIT WHEN SQLCODE <> -1940;
    EXCEPTION
      WHEN cannot_drop_user THEN
        --DBMS_OUTPUT.PUT_LINE(SQLERRM);
        DBMS_OUTPUT.PUT_LINE('Waiting ' || sleep_interval || ' seconds for resource clean-up...');
        DBMS_LOCK.SLEEP(sleep_interval);
      WHEN OTHERS THEN
        DBMS_OUTPUT.PUT_LINE('Inner: ' || SQLERRM);
    END;
  END LOOP;
  DBMS_OUTPUT.PUT_LINE('Exiting loop with SQLCODE: ' || SQLCODE);
  DBMS_OUTPUT.PUT_LINE('User ' || in_username || ' has been dropped.');


EXCEPTION
  WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE('Outer: ' || SQLERRM);
END;
/
SAMPLE OUTPUT


SQL*Plus: Release 10.1.0.4.0 - Production on Tue Sep 6 15:34:47 2005
Copyright (c) 1982, 2005, Oracle. All rights reserved.


Connected to:
Oracle Database 10g Enterprise Edition Release 10.1.0.4.0 - Production
With the Partitioning, OLAP and Data Mining options


SQL> CONNECT sys/change_on_install@orcl AS SYSDBA
Connected.
SQL> GRANT connect, resource TO test IDENTIFIED BY test;


Grant succeeded.


SQL> @"C:\scripts\kill_drop_user.sql"
Procedure created.


SQL> SET serveroutput ON size 1000000


SQL> SET timing ON


SQL> EXEC kill_drop_user('TEST');
Killing user 152, 6915
Killing user 153, 326
Killing user 154, 156
Attempting to drop user TEST...
Waiting 10 seconds for resource clean-up...
Attempting to drop user TEST...
Exiting loop with SQLCODE: 0
User TEST has been dropped.


PL/SQL procedure successfully completed.


Elapsed: 00:00:10.71


SQL> -- verify user has been dropped
SQL> CONNECT test/test@orcl
ERROR:
ORA-01017: invalid username/password; logon denied




Warning: You are no longer connected to ORACLE.
SQL> 






轉自MOS
如何殺掉一個用戶下的所有進程并drop掉這個用戶


Copy the sample code below into a file named kill_drop_user.sql.
Open SQL*Plus and connect as user SYS to your database
SQL> CONNECT sys/change_on_install@orcl AS SYSDBA
Create a user called TEST with password TEST
SQL> GRANT connect, resource TO test IDENTIFIED BY test;
Create the procedure kill_drop_user
SQL> @"C:\scripts\kill_drop_user.sql"
Open three (3) SQL*Plus sessions and connect as user TEST.
Execute the PL/SQL script
SQL> SET serveroutput ON size 1000000 SQL> SET timing ON SQL> EXEC kill_drop_user('TEST');
CAUTION


This sample code is provided for educational purposes only, and is not supported by Oracle Support. It has been tested internally, however, we do not guarantee that it will work for you. Ensure that you run it in your test environment before using.
SAMPLE CODE


CREATE OR REPLACE PROCEDURE kill_drop_user (in_username IN VARCHAR2,
                                            sleep_interval IN NUMBER DEFAULT 10)
AS
  PRAGMA AUTONOMOUS_TRANSACTION;


  cannot_drop_user EXCEPTION;
  PRAGMA EXCEPTION_INIT(cannot_drop_user, -1940);


  user_count    NUMBER := -1;


BEGIN


  SELECT count(*) INTO user_count FROM dba_users WHERE username = in_username;
  IF user_count = 0 THEN
    DBMS_OUTPUT.PUT_LINE('User ' || in_username || ' does not exist.');
    RETURN;
  END IF;


  FOR i IN (SELECT sid, serial# FROM v$session WHERE username = in_username) LOOP
    EXECUTE IMMEDIATE 'alter system kill session ' || '''' || i.sid || ',' || i.serial# || ''' immediate';
    DBMS_OUTPUT.PUT_LINE('Killing user ' || i.sid || ', ' || i.serial#);
  END LOOP;


  LOOP
    BEGIN
      DBMS_OUTPUT.PUT_LINE('Attempting to drop user ' || in_username || '...');
      EXECUTE IMMEDIATE 'DROP USER ' || in_username || ' CASCADE';


      EXIT WHEN SQLCODE <> -1940;
    EXCEPTION
      WHEN cannot_drop_user THEN
        --DBMS_OUTPUT.PUT_LINE(SQLERRM);
        DBMS_OUTPUT.PUT_LINE('Waiting ' || sleep_interval || ' seconds for resource clean-up...');
        DBMS_LOCK.SLEEP(sleep_interval);
      WHEN OTHERS THEN
        DBMS_OUTPUT.PUT_LINE('Inner: ' || SQLERRM);
    END;
  END LOOP;
  DBMS_OUTPUT.PUT_LINE('Exiting loop with SQLCODE: ' || SQLCODE);
  DBMS_OUTPUT.PUT_LINE('User ' || in_username || ' has been dropped.');


EXCEPTION
  WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE('Outer: ' || SQLERRM);
END;
/
SAMPLE OUTPUT


SQL*Plus: Release 10.1.0.4.0 - Production on Tue Sep 6 15:34:47 2005
Copyright (c) 1982, 2005, Oracle. All rights reserved.


Connected to:
Oracle Database 10g Enterprise Edition Release 10.1.0.4.0 - Production
With the Partitioning, OLAP and Data Mining options


SQL> CONNECT sys/change_on_install@orcl AS SYSDBA
Connected.
SQL> GRANT connect, resource TO test IDENTIFIED BY test;


Grant succeeded.


SQL> @"C:\scripts\kill_drop_user.sql"
Procedure created.


SQL> SET serveroutput ON size 1000000


SQL> SET timing ON


SQL> EXEC kill_drop_user('TEST');
Killing user 152, 6915
Killing user 153, 326
Killing user 154, 156
Attempting to drop user TEST...
Waiting 10 seconds for resource clean-up...
Attempting to drop user TEST...
Exiting loop with SQLCODE: 0
User TEST has been dropped.


PL/SQL procedure successfully completed.


Elapsed: 00:00:10.71


SQL> -- verify user has been dropped
SQL> CONNECT test/test@orcl
ERROR:
ORA-01017: invalid username/password; logon denied




Warning: You are no longer connected to ORACLE.
SQL> 






轉自MOS


Copy the sample code below into a file named kill_drop_user.sql.
Open SQL*Plus and connect as user SYS to your database
SQL> CONNECT sys/change_on_install@orcl AS SYSDBA
Create a user called TEST with password TEST
SQL> GRANT connect, resource TO test IDENTIFIED BY test;
Create the procedure kill_drop_user
SQL> @"C:\scripts\kill_drop_user.sql"
Open three (3) SQL*Plus sessions and connect as user TEST.
Execute the PL/SQL script
SQL> SET serveroutput ON size 1000000 SQL> SET timing ON SQL> EXEC kill_drop_user('TEST');
CAUTION


This sample code is provided for educational purposes only, and is not supported by Oracle Support. It has been tested internally, however, we do not guarantee that it will work for you. Ensure that you run it in your test environment before using.
SAMPLE CODE


CREATE OR REPLACE PROCEDURE kill_drop_user (in_username IN VARCHAR2,
                                            sleep_interval IN NUMBER DEFAULT 10)
AS
  PRAGMA AUTONOMOUS_TRANSACTION;


  cannot_drop_user EXCEPTION;
  PRAGMA EXCEPTION_INIT(cannot_drop_user, -1940);


  user_count    NUMBER := -1;


BEGIN


  SELECT count(*) INTO user_count FROM dba_users WHERE username = in_username;
  IF user_count = 0 THEN
    DBMS_OUTPUT.PUT_LINE('User ' || in_username || ' does not exist.');
    RETURN;
  END IF;


  FOR i IN (SELECT sid, serial# FROM v$session WHERE username = in_username) LOOP
    EXECUTE IMMEDIATE 'alter system kill session ' || '''' || i.sid || ',' || i.serial# || ''' immediate';
    DBMS_OUTPUT.PUT_LINE('Killing user ' || i.sid || ', ' || i.serial#);
  END LOOP;


  LOOP
    BEGIN
      DBMS_OUTPUT.PUT_LINE('Attempting to drop user ' || in_username || '...');
      EXECUTE IMMEDIATE 'DROP USER ' || in_username || ' CASCADE';


      EXIT WHEN SQLCODE <> -1940;
    EXCEPTION
      WHEN cannot_drop_user THEN
        --DBMS_OUTPUT.PUT_LINE(SQLERRM);
        DBMS_OUTPUT.PUT_LINE('Waiting ' || sleep_interval || ' seconds for resource clean-up...');
        DBMS_LOCK.SLEEP(sleep_interval);
      WHEN OTHERS THEN
        DBMS_OUTPUT.PUT_LINE('Inner: ' || SQLERRM);
    END;
  END LOOP;
  DBMS_OUTPUT.PUT_LINE('Exiting loop with SQLCODE: ' || SQLCODE);
  DBMS_OUTPUT.PUT_LINE('User ' || in_username || ' has been dropped.');


EXCEPTION
  WHEN OTHERS THEN
    DBMS_OUTPUT.PUT_LINE('Outer: ' || SQLERRM);
END;
/
SAMPLE OUTPUT


SQL*Plus: Release 10.1.0.4.0 - Production on Tue Sep 6 15:34:47 2005
Copyright (c) 1982, 2005, Oracle. All rights reserved.


Connected to:
Oracle Database 10g Enterprise Edition Release 10.1.0.4.0 - Production
With the Partitioning, OLAP and Data Mining options


SQL> CONNECT sys/change_on_install@orcl AS SYSDBA
Connected.
SQL> GRANT connect, resource TO test IDENTIFIED BY test;


Grant succeeded.


SQL> @"C:\scripts\kill_drop_user.sql"
Procedure created.


SQL> SET serveroutput ON size 1000000


SQL> SET timing ON


SQL> EXEC kill_drop_user('TEST');
Killing user 152, 6915
Killing user 153, 326
Killing user 154, 156
Attempting to drop user TEST...
Waiting 10 seconds for resource clean-up...
Attempting to drop user TEST...
Exiting loop with SQLCODE: 0
User TEST has been dropped.


PL/SQL procedure successfully completed.


Elapsed: 00:00:10.71


SQL> -- verify user has been dropped
SQL> CONNECT test/test@orcl
ERROR:
ORA-01017: invalid username/password; logon denied




Warning: You are no longer connected to ORACLE.
SQL> 






轉自MOS
向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

久治县| 鲁山县| 沙洋县| 天水市| 灵丘县| 锦州市| 会同县| 固安县| 沽源县| 衡东县| 丰台区| 鹿邑县| 吴川市| 南宁市| 红河县| 北辰区| 闽侯县| 清流县| 常州市| 莒南县| 宜昌市| 嘉兴市| 利辛县| 锡林郭勒盟| 佳木斯市| 额敏县| 屏边| 玛曲县| 封开县| 东丰县| 景泰县| 十堰市| 西乌珠穆沁旗| 太原市| 华池县| 漳平市| 略阳县| 诸城市| 金昌市| 东山县| 鱼台县|