今天使用oraclepl/sql遇到锁表情况,以前也遇到过都是用完忘了,今天记录下。
1、先登录数据库,使用以下查询语句查询出哪个对象被锁
select t2.username,
t2.sid,
t2.serial#,
t3.object_name,
t2.osuser,
t2.machine,
t2.program,
t2.logon_time,
t2.command,
t2.lockwait,
t2.saddr,
t2.paddr,
t2.taddr,
t2.sql_address,
t1.locked_mode
from v$locked_object t1, v$session t2, dba_objects t3
where t1.session_id = t2.sid
and t1.object_id = t3.object_id
order by t2.logon_time;
2、使用alter语句修改被锁
alter system kill session ‘sid,seial#’; –sid,seial#为上一个语句查出的
3、还有实用查询正在使用中的sql可以快速定位到哪个操作导致锁表。
select /*+ ordered */
sql_text
from v$sqltext a
where (a.hash_value, a.address) in
(select decode(sql_hash_value, 0, prev_hash_value, sql_hash_value),
decode(sql_hash_value, 0, prev_sql_addr, sql_address)
from v$session b
where b.sid = ‘1162’) /* 此处1162 为sid*/
order by piece asc;