oracle数据库锁,解锁,批量解锁

-- 1. 查看被锁的表
SELECT p.spid, a.serial#, c.object_name, b.session_id, b.oracle_username,b.os_user_name
 FROM v$process p, v$session a, v$locked_object b, all_objects c
 WHERE p.addr = a.paddr 
 AND a.process = b.process
 AND c.object_id = b.object_id
-- 2. 查看是哪个进程锁的 
SELECT sid, serial#, username, status, osuser FROM v$session  where serial# = '11016'
 
-- 3. 杀掉这个进程  
alter system kill session '72,11016';

-- 4.批量解锁
declare cursor mycur is   
select b.sid,b.serial#   
  from v$locked_object a,v$session b   
  where a.session_id = b.sid group by b.sid,b.serial#;   
begin   
  for cur in mycur   
    loop     
     execute immediate ( 'alter system  kill session  '''||cur.sid || ','|| cur.SERIAL# ||''' ');   
     end loop;   
end;

你可能感兴趣的:(oracle)