Thanks for the question, Joe.
Asked: January 18, 2016 - 10:38 am UTC
Last updated: January 20, 2016 - 4:11 pm UTC
Version: 11.2.0.4
Viewed 1000+ times
You Asked
Hi, Tom
Today, I was trying to collect the current running SQL statements which elapsed more than 10 seconds per execution. To caculate the SQL Elapsed time, I have tried some SQL dictionary views (such as gv$sql, gv$sqlarea, gv$transaction, gv$session), but the "Elapsed_time" column on these views just present the total Elapsed time for a SQL statment, rather than per executions. SO I had to divide the "Elpased time" into "Executions", like the SQL Statments shown below:
SELECT A.SID,A.SERIAL#,S.ELAPSED_TIME/1000000,executions,A.PROGRAM,S.SQL_TEXT,S.SQL_ID FROM GV$SESSION A,GV$SQL S
WHERE A.SQL_HASH_VALUE = S.HASH_VALUE
AND ROUND(ELAPSED_TIME / 1000000 / (CASE
WHEN (EXECUTIONS = 0 OR NVL(EXECUTIONS, 1 ) = 1) THEN
1
ELSE
EXECUTIONS
END),
2)> 10
AND UPPER(SQL_TEXT) LIKE 'SELECT%'
AND A.STATUS = 'ACTIVE';
Is there any SQL dictionary view records the SQL per execution time, rather than total elapsed time?
and Connor said...
Not directly, but you could use V$ACTIVE_SESSION_HISTORY to get a good idea of it. Something like
select sql_id, sql_exec_id, count(*)
from V$ACTIVE_SESSION_HISTORY
group by sql_id, sql_exec_id
having count(*) > 10
Hope this helps.
Rating
(3 ratings)
Is this answer out of date? If it is, please let us know via a Comment