Oracle查询数据库锁表和解除锁表

前端之家收集整理的这篇文章主要介绍了Oracle查询数据库锁表和解除锁表前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

oracle查询被锁定的表:

SELECT p.spid,c.object_name,b.session_id,a.serial#,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;

解除表的锁定:
DECLARE
  S_CMD VARCHAR2(2000);
BEGIN
  FOR X IN (SELECT p.spid,all_objects c
 WHERE p.addr = a.paddr
  AND a.process = b.process
  AND c.object_id = b.object_id) LOOP
     S_CMD := ''''||X.SESSION_ID||','||X.SERIAL#||'''';     
     BEGIN
       execute immediate 'alter system kill session '||S_CMD;
     exception
      when others then 
      DBMS_OUTPUT.PUT_LINE(sqlCODE||'---'||sqlERRM);
     end;    
  END LOOP;
END;
原文链接:https://www.f2er.com/oracle/206688.html

猜你在找的Oracle相关文章