oracle drop user

  1. SQL> drop user test cascade;   
  2. drop user test cascade  
  3. *   
  4. ERROR at line 1:   
  5. ORA-01940: cannot drop a user that is currently connected   
  6.   
  7.   
  8. SQL> select username,sid,serial# from v$session;   
  9.   
  10. USERNAME                   SID     SERIAL#   
  11. ------------------------------ ---------- ----------   
  12. SYSMAN                     118       43411   
  13. test                       122     483   
  14. test                       123     391   
  15. SYS                        125     626   
  16. DBSNMP                     129      48   
  17. SYSMAN                     130     247   
  18. DBSNMP                     136     113   
  19. SYSMAN                     138      15   
  20. SYSMAN                     141       3   
  21.                                143       50435   
  22.                                152       3   
  23.   
  24.   
  25. USERNAME                   SID     SERIAL#   
  26. ------------------------------ ---------- ----------   
  27.                        153       3   
  28. SYSMAN                 158      15   
  29.                        160       1   
  30.                        161       1   
  31.                        162       1   
  32.                        163       1   
  33.                        164       1   
  34.                        165       1   
  35.                        166       1   
  36.                        167       1   
  37.                        168       1   
  38.   
  39. USERNAME                   SID     SERIAL#   
  40. ------------------------------ ---------- ----------   
  41.                        169       1   
  42.                        170       1   
  43.   
  44. SQL>alter system kill session '122,483';   
  45.   
  46. SQL> drop user test cascade;   
  47. (**)如果在drop 后还提示ORA-01940:无法删除当前已链接的用户,说明还有连接的session,可以通过查看session的状态来确定该session是否被kill 了,用如下语句查看:

    -------------------------------------

    select saddr,sid,serial#,paddr,username,status from v$session where username is not null

    结果如下(以我的库为例):

    saddr                     sid          serial#            paddr              username              status

    --------------------------------------------------------------------------------------------------------

    564A1E28              513           22974            569638F4       NETBNEW             ACTIVE
    564A30DC              514          18183             569688CC        NETBNEW           INACTIVE
    564A5644             516           21573            56963340       NETBNEW            INACTIVE
    564B6ED0              531         9                   56962D8C        NETBNEW            INACTIVE
    564B8184              532          4562                56A1075C        WUZHQ                KILLED

     

    status 为要删除用户的session状态,如果还为inactive,说明没有被kill掉,如果状态为killed,说明已kill。

    由此可见,WUZHQ这个用户的session已经被杀死。此时可以安全删除用户。

      
  48. User dropped.  

你可能感兴趣的:(oracle)