数据库锁表查看与解锁
/*查看被锁的会话*/
SELECT SN.USERNAME,
M.SID,
SN.SERIAL#,
M.TYPE,
DECODE(M.LMODE, 0, 'None', 1, 'Null', 2, 'Row Share', 3, 'Row Excl.', 4, 'Share', 5, 'S/Row Excl.', 6, 'Exclusive', LMODE, LTRIM(TO_CHAR(LMODE, '990')) ) LMODE,
DECODE(M.REQUEST, 0, 'None', 1, 'Null', 2, 'Row Share', 3, 'Row Excl.', 4, 'Share', 5, 'S/Row Excl.', 6, 'Exclusive', REQUEST, LTRIM(TO_CHAR(M.REQUEST, '990')) ) REQUEST,
M.ID1,
M.ID2
FROM V$SESSION SN, V$LOCK M
WHERE (SN.SID = M.SID AND M.REQUEST != 0) --存在锁请求,即被阻塞
OR (SN.SID = M.SID --不存在锁请求,但是锁定的对象被其他会话请求锁定
AND M.REQUEST = 0 AND LMODE != 4 AND (ID1, ID2) IN (
SELECT S.ID1, S.ID2
FROM V$LOCK S
WHERE REQUEST != 0
AND S.ID1 = M.ID1
AND S.ID2 = M.ID2) ) ORDER BY ID1, ID2, M.REQUEST;
/*将数据库中被锁表解锁*/
ALTER SYSTEM KILL SESSION 'sid,SERIAL#';