日期:2014-05-16  浏览次数:20565 次

检测死锁并杀死会话

begin
for c in (select t3.OBJECT_NAME,t2.SID,t2.SERIAL#,t2.USERNAME,'alter system kill session '||chr(39)|| t2.SID||','||t2.SERIAL#||chr(39)||' immediate' as fkill from v$locked_object t1,v$session? t2,all_objects t3
? where t1.SESSION_ID = t2.SID and t3.OBJECT_ID = t1.OBJECT_ID)
loop
??? begin
??? dbms_output.put_line(c.fkill);
??? execute immediate c.fkill;
??? exception
????? when others then null;
????? end;
end loop;
end;