Active Session History Longest SQL

 SELECT
        STAT.INSTANCE_NUMBER,
        STAT.SQL_ID,
         SQL_TEXT,
         PLAN_HASH_VALUE,
         PARSING_SCHEMA_NAME,
         ELAPSED_TIME_DELTA/1000000 SECONDS,
         round((ELAPSED_TIME_DELTA/1000000)/60,2) MINUTES,
         (ELAPSED_TIME_DELTA/1000000) / EXECUTIONS_DELTA,
         round((ELAPSED_TIME_DELTA/1000000)/60 / EXECUTIONS_DELTA,2) "TIME PER EXEC",
         STAT.SNAP_ID,
         SS.END_INTERVAL_TIME,
         EXECUTIONS_DELTA
    FROM DBA_HIST_SQLSTAT STAT, DBA_HIST_SQLTEXT TXT, DBA_HIST_SNAPSHOT SS
   WHERE     STAT.SQL_ID = TXT.SQL_ID
         AND STAT.DBID = TXT.DBID
         AND SS.DBID = STAT.DBID
         AND SS.INSTANCE_NUMBER = STAT.INSTANCE_NUMBER
         AND STAT.SNAP_ID = SS.SNAP_ID
         AND PARSING_SCHEMA_NAME = 'SCOTT'
         AND SS.BEGIN_INTERVAL_TIME >= SYSDATE - 5
         AND ELAPSED_TIME_DELTA >= round((8/1000000))
         AND PLAN_HASH_VALUE <> 0
         AND EXECUTIONS_DELTA > 1
ORDER BY 6 desc;

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.