-- 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;
//-----------------------------------//
或者这个查询删除锁
alter system kill session 'sid,serial#';
SELECT a_s.owner,
a_s.object_name,
a_s.object_type,
VN.SID,
VN.SERIAL#,
VS.SPID "OS_PID",
VN.PROCESS "CLIENT_PID",
VN.USERNAME,
VN.OSUSER,
VN.MACHINE "HOSTNAME" ,
VN.TERMINAL,
VN.PROGRAM,
TO_CHAR(VN.LOGON_TIME,'YYYY-MM-DD HH24:MI:SS')"LOGIN_TIME",
'alter system kill session '''||vn.sid||','||vn.serial#||''';' "ORACKE_KILL",
'kill -9 '|| VS.SPID "OS_KILL"
FROM ALL_OBJECTS A_S,
V$LOCKED_OBJECT V_T,
V$SESSION VN,
V$PROCESS VS
WHERE A_S.OBJECT_ID=V_T.OBJECT_ID
AND V_T.SESSION_ID =VN.SID
AND VS.ADDR=VN.PADDR
AND VN.USERNAME NOT IN('SYSMAN','SYS');