Oracle数据库锁表解决办法

1.输入查锁语句

 SELECT s.sid, s.serial#,b.object_name, s.username, s.schemaname, s.osuser, s.process, s.machine,
s.terminal, s.logon_time, l.type
FROM v$session s, v$lock l,v$locked_object a,dba_objects b
WHERE s.sid = l.sid and b.object_id = a.object_id and a.session_id=s.sid
AND s.username IS NOT NULL
ORDER BY s.sid;
 

2.查询到FD_QXS_BUY_BOOK表被锁

 

 

3.杀单个锁语句

alter system kill session'SID,SERIAL#'

 

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;

 

4.完美解决

为什么会锁表呢,因为在开发过程中可能同时又多个人在操作同一张表,你在查询的同时别人在修改就可能导致锁表。

你可能感兴趣的:(Oracle数据库锁表解决办法)