1. 程式人生 > >ORA-01940 刪除當前已連線使用者, 匯入新資料

ORA-01940 刪除當前已連線使用者, 匯入新資料

1)檢視使用者的連線狀況

select username,sid,serial# from v$session

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

如下結果:

username          sid                serial#

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

NETBNEW          513              22974
NETBNEW          514              18183
NETBNEW          516              21573
NETBNEW          531              9
WUZHQ             532              4562

(2)找到要刪除使用者的sid,和serial,並刪除

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

如:你要刪除使用者'WUZHQ',可以這樣做:

alter system kill session'532,4562'

(3)刪除使用者

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

drop user username cascade

(**)如果在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已經被殺死。此時可以安全刪除使用者。

create user ONEPLATFORM IDENTIFIED BY ONEPLATFORM;

GRANT CREATE USER,DROP USER,ALTER USER ,CREATE ANY VIEW ,

DROP ANY VIEW,EXP_FULL_DATABASE,IMP_FULL_DATABASE,

DBA,CONNECT,RESOURCE,CREATE SESSION  TO ONEPLATFORM;

grant dba to ONEPLATFORM;

imp userid=ONEPLATFORM/[email protected] full=y file=D:\data\ONEPLATFORM_2018_08_31_01.dmp