SELECT v.SQL_TEXT,m.* FROM (select distinct snap_id, sql_id, EXECUTIONS_DELTA, trunc(max(ELAPSED_TIME_DELTA) OVER(PARTITION BY snap_id, sql_id) / 1000000, 0) max_elapsed, trunc((max(ELAPSED_TIME_DELTA) OVER(PARTITION BY snap_id, sql_id)) / (SUM(ELAPSED_TIME_DELTA) OVER(PARTITION BY snap_id)), 2) * 100 per_total from dba_hist_sqlstat t WHERE T.snap_id IN (SELECT MAX(snap_id) FROM dba_hist_sqlstat) ) M,v$sql v where m.sql_id=v.sql_id and m.max_elapsed>=30
直接上代码
上面代码还是有个问题,SQL过长的时候,SQL展示不全。用下面可以。执行时间超过30秒的,都会被查询出来,你可以改时间。
SELECT v.SQL_FULLTEXT,m.* FROM (select distinct snap_id, sql_id, EXECUTIONS_DELTA, trunc(max(ELAPSED_TIME_DELTA) OVER(PARTITION BY snap_id, sql_id) / 1000000, 0) max_elapsed, trunc((max(ELAPSED_TIME_DELTA) OVER(PARTITION BY snap_id, sql_id)) / (SUM(ELAPSED_TIME_DELTA) OVER(PARTITION BY snap_id)), 2) * 100 per_total from dba_hist_sqlstat t WHERE T.snap_id IN (SELECT MAX(snap_id) FROM dba_hist_sqlstat) ) M,v$sqlarea v where m.sql_id=v.sql_id and m.max_elapsed>=30
------------正 文 已 结 束, 感 谢 您 的 阅 读 (折雨的天空)--------------------
转载请注明本文标题和链接:《Oracle查询慢SQL的语句》
发表评论