刪除資料庫使用者

2021-06-02 20:52:06 字數 1856 閱讀 1869

#!/usr/bin/ksh

#################################

# 1、upload the shell command to the server

# 2、grant the 777 to the command

# 3、use method like as follow: ./dropuser.sh username

# the username as the parameter for the shell command

# and the username is not distinguish the upper and lowwer

##################################

echo "start delete link"

username=$1;

username=`echo $username |tr "[a-z]" "[a-z]"`;

querysessionnum=`sqlplus / as sysdba << eof

select count(*) from v\\$session where username='$username';

select sid,serial# from v\\$session where username='$username';

eof`

droplink=`sqlplus / as sysdba << eof

drop user $username cascade;

eof`

sessionnum=`echo $querysessionnum | awk -f'sql>' '' | awk -f' ---------- ' ''`

echo "link number :"$sessionnum

if [ $sessionnum = 0 ]

then

temp=`echo $droplink`

exit

fi    

sessionsidser=`echo $querysessionnum | awk -f'sql>' ''`

i=2while true

dosessionsids=`echo $sessionsidser | awk -f'sid serial# ---------- ----------' '' | awk -f'rows selected.' ''`

if [ "x$sessionsids" = "x" ]

then

break;

finumindex=1

while true

dosessionsidone=`echo $sessionsids | awk -f' ' ''`

if [ "x$sessionsidone" = "x" ]

then

break;

filet numindex=numindex+1

sessionsidtwo=`echo $sessionsids | awk -f' ' ''`

if [ "x$sessionsidtwo" = "x" ]

then

break;

filet numindex=numindex+1

echo "alter system kill session  '$sessionsidone,$sessionsidtwo';" >> dellik.sql

done

let i=i+1    

done

sqlplus / as sysdba << eof

@dellik.sql

eofrm dellik.sql

temp=`echo $droplink`

轉刪除資料庫使用者時占用

ora 01940 無法刪除當前已鏈結的使用者 1 檢視使用者的連線狀況 select username,sid,serial from v session 如下結果 username sid serial netbnew 513 22974 netbnew 514 18183 netbnew 51...

Oracle資料庫 刪除資料庫

1 單擊 開始 oracle oradb12home1 database configuration assistant 進入刪除步驟的第一步,選擇 刪除資料庫 2 單擊 下一步 按鈕,如圖所示。在資料庫列表中選擇需要刪除的資料,例如test,並輸入使用者名稱和口令。3 單擊 下一步 按鈕,開啟 管...

阻止使用者(除SA使用者)刪除資料庫表

物件 ddltrigger tr safety table 指令碼日期 06 07 2011 14 20 06 set ansi nulls on goset quoted identifier on go author create date 2010 04 03 description 除了sa...