我在Oracle 11g数据库中运行的查询很少,这些查询是可重复的查询。我想查找基于sql_id或sql_text执行每天执行所花费的日期和时间的次数?有没有办法找到这个?
答案 0 :(得分:1)
执行次数在AWR报告中。这意味着它也可能来自DBA_HIST_表,但我不知道哪一个。根据您之前的问题,我假设您已获得AWR许可。
--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
...