declare
--类型定义
cursor c_cur
is
--查询锁表进程
SELECT object_name, machine, s.sid, s.serial#
FROM gv$locked_object l, dba_objects o, gv$session s
WHERE l.object_id = o.object_id
AND l.session_id = s.sid;

c_row c_cur%rowtype;
begin
open c_cur;
loop

fetch c_cur into c_row;

exit when c_cur%notfound;
--
dbms_output.put_line('alter system kill session '''||c_row.sid||''','''||c_row.serial#||'''');
--杀死锁表进程
execute immediate 'alter system kill session '''||c_row.sid||','||c_row.serial#||'''';
end loop;
--关闭游标
close c_cur;
end;

05-11 16:27