查询长事务SQL
查询长事务SQL
下面SQL 查询数据库中正在执行大于N秒的事务信息:
with ltr as ( select to_char(sysdate,'YYYYMMDDHH24MISS') TM, s.sid, s.sql_id, s.sql_child_number, s.prev_sql_id, xid, to_char(t.start_date,'YYYYMMDDHH24MISS') start_time, e.TYPE,e.block, e.ctime, decode(e.CTIME, 0, (sysdate - t.start_date) * 3600*24, e.ctime) el_second -- q.sql_text from v$transaction t, v$session s,v$transaction_enqueue e where t.start_date <= sysdate - interval '100' second /*查询开始多少秒的事务*/ and t.addr = s.taddr --and s.sql_child_number = q.CHILD_NUMBER(+) --and s.sql_id = q.sql_id(+) and s.prev_sql_id = q.sql_id(+) and t.addr = e.addr(+) ) select ltr.* , (select q1.sql_text from v$sql q1 where ltr.prev_sql_id = q1.sql_id(+) and rownum = 1) prev_sql_text , (select q1.sql_text from v$sql q1 where ltr.sql_id = q1.sql_id(+) and ltr.sql_child_number = q1.CHILD_NUMBER(+)) sql_text from ltr ltr;