`

Oracle批量杀死锁.sql

 
阅读更多
declare
  cursor mycur is
    select s.sid, s.serial#
      from v$session s, v$lock l, dba_objects o
     where l.sid = s.sid
       and l.id1 = o.object_id(+)
       and o.object_name = 'table_name';

  newcount number;

begin

  for cur in mycur loop
 
    select count(1)
      into newcount
      from v$locked_object a, v$session b
     where a.session_id = b.sid
       and b.sid = cur.sid
       and b.serial# = cur.serial#;
 
    if newcount >= 1 then
   
      execute immediate ('alter system  kill session  ''' || cur.sid || ',' ||
                        cur.serial# || ''' ');
    end if;
 
  end loop;

end;
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics