user3225011
user3225011

Reputation: 161

how to find number of times query executed?

I have few queries running in Oracle 11g database from application those are repeatable queries. I want to find number of times the query executed for the day and time it took for each execution based on sql_id or sql_text? Is there a way to find this?

Upvotes: 2

Views: 5220

Answers (2)

Dinesh vishe
Dinesh vishe

Reputation: 3608

you can check query execution in AWR report.

enter image description here

Upvotes: 0

Jon Heller
Jon Heller

Reputation: 36922

The number of executions is in the AWR reports. Which means it can probably also be derived from a DBA_HIST_ table but I don't know which one. Based on your previous question I assume you have AWR licensed.

--Find the SQL_ID.  If not in shared_pool it should be in a historical table.
select * from v$sql where sql_fulltext like ...;
select * from dba_hist_sqltext where sql_text like ...;

--Find the begin and end snapshot periods.
--Be careful here, I've seen some weird timezone issues, it can be annoyingly
--difficult to get the exact period of time you want.
select * from dba_hist_snapshot order by begin_interval_time desc;

--Get AWR report.
select dbms_workload_repository.awr_sql_report_text(l_dbid => 3037785498
  , l_inst_num => 1, l_bid => 53007, l_eid => 53020, l_sqlid => '57pfs5p8xc07w')
from dual;


WORKLOAD REPOSITORY SQL Report

Snapshot Period Summary

...

    Plan Hash           Total Elapsed                 1st Capture   Last Capture
#   Value                    Time(ms)    Executions       Snap ID        Snap ID
--- ---------------- ---------------- ------------- ------------- --------------
1   1329243004                    376           552         53008          53018

...

Upvotes: 2

Related Questions