大橙子网站建设,新征程启航

为企业提供网站建设、域名注册、服务器等服务

安全地删除数据库用户

SET SERVEROUT ON

成都创新互联公司专业为企业提供四方台网站建设、四方台做网站、四方台网站设计、四方台网站制作等企业网站建设、网页设计与制作、四方台企业网站模板建站服务,十多年四方台做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。

CREATE OR REPLACE PROCEDURE gracefullyDropUser(v_username IN VARCHAR2) IS
l_cnt integer;
sqlStmt VARCHAR2(1000);
BEGIN
sqlStmt := 'alter user ' || v_username || ' account lock'; --锁住用户,防止其他新会话的连接
EXECUTE IMMEDIATE sqlStmt;
dbms_output.put_line(sqlStmt);
FOR x IN (SELECT * FROM v$session WHERE username = v_username) LOOP
sqlStmt := 'alter system disconnect session ''' || x.sid || ',' ||
x.serial# || ''' IMMEDIATE'; --循环disconnect每一个已存的session连接,并等待所有session被删除
EXECUTE IMMEDIATE sqlStmt;
dbms_output.put_line(sqlStmt);
END LOOP;

-- Wait until all sessions are disconnected forcely, check every 2 seconds
LOOP
SELECT COUNT(*) INTO l_cnt FROM v$session WHERE username = v_username;
EXIT WHEN l_cnt = 0;
dbms_lock.sleep(2);
dbms_output.put_line('hold on ...');
END LOOP;
sqlStmt := 'drop user ' || v_username || ' cascade'; --安全地删除数据库用户
EXECUTE IMMEDIATE sqlStmt;
dbms_output.put_line(sqlStmt);
END gracefullyDropUser;
/

execute gracefullyDropUser('AGILE');
alter user AGILE account lock
alter system disconnect session '12,97' IMMEDIATE
alter system disconnect session '20,11' IMMEDIATE
alter system disconnect session '141,118' IMMEDIATE
hold on ...
hold on ...
drop user AGILE cascade

PL/SQL procedure successfully completed.


网页标题:安全地删除数据库用户
转载来源:http://dzwzjz.com/article/pejgpo.html
在线咨询
服务热线
服务热线:028-86922220
TOP