欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

Oracle数据库查询对象是否被锁定及解锁

程序员文章站 2023-12-31 09:26:16
...

Oracle数据库对象是否被锁定查询SQL及解锁过程SQL详见下面:

Oracle数据库对象是否被锁定查询SQL及解锁过程SQL详见下面:

--查询当前用户下被锁的对象
SELECT B.OBJECT_NAME, B.OWNER, C.SID,C.SERIAL#,C.OSUSER, C.MACHINE, C.TERMINAL
FROM V$LOCKED_OBJECT A, DBA_OBJECTS B, V$SESSION C
WHERE A.OBJECT_ID = B.OBJECT_ID
AND A.SESSION_ID = C.SID
AND c.STATUS='INACTIVE'
AND C.TYPE='USER'
ORDER BY 1;

--解锁语句
DECLARE
V_SQL VARCHAR2(500);
CURSOR C_SESSION IS
SELECT B.OBJECT_NAME,
B.OWNER,
C.SID AS SESSION_ID,
C.SERIAL# AS SERIAL#,
C.OSUSER,
C.MACHINE,
C.TERMINAL
FROM V$LOCKED_OBJECT A, DBA_OBJECTS B, V$SESSION C
WHERE A.OBJECT_ID = B.OBJECT_ID AND A.SESSION_ID = C.SID
AND C.STATUS = 'INACTIVE' AND C.TYPE = 'USER'
ORDER BY 1;
BEGIN
FOR GET_SESSION IN C_SESSION
LOOP
BEGIN
V_SQL:='ALTER SYSTEM KILL SESSION '''||GET_SESSION.SESSION_ID||','||GET_SESSION.SERIAL#||''' IMMEDIATE';
EXECUTE IMMEDIATE V_SQL;
EXCEPTION
WHEN OTHERS THEN
NULL;
END;
END LOOP;
END;
/

Linux-6-64下安装Oracle 12C笔记

RHEL6.4_64安装单实例Oracle 12cR1

Oracle 12C新特性之翻页查询

解读 Oracle 12C 的 12 个新特性

上一篇:

下一篇: