1.提取&beg_snap 、&end_snap、&dbid、$inst_num
--提取&beg_snap 、&end_snap
select * from dba_hist_snapshot x --where x.BEGIN_INTERVAL_TIME > trunc(sysdate)
order by x.BEGIN_INTERVAL_TIME desc
--提取 1766956972
select dbid from v$database;
--提取$inst_num = 1
select * from v$instance;
- SQL ordered by Elapsed Time
select * from
(
select round(nvl((sqt.elap / 1000000), to_number(null)),2) "Elapsed Time(s)",
round( nvl((sqt.cput / 1000000), to_number(null)),2) "CPU Time(s)",
sqt.exec,
round(decode(sqt.exec, 0, to_number(null),(sqt.elap / sqt.exec / 1000)),2) "Elap per Exec(ms)",
round
(
(
100 * (
sqt.elap / (
select sum(e.value) - sum(b.value)
from dba_hist_sys_time_model b,dba_hist_sys_time_model e
where b.snap_id = &beg_snap and
e.snap_id = &end_snap and
b.dbid = 1766956972 and
e.dbid = 1766956972 and
b.instance_number = 1 and
e.instance_number = 1 and
e.stat_name = 'DB time' and
b.stat_name = 'DB time'
)
)
) ,2
) norm_val ,
sqt.sql_id,sqt.begin_time,sqt.end_time,
decode(sqt.module, null, null, 'Module: ' || sqt.module) SqlModule,
nvl(to_nchar(SUBSTR(st.sql_text,1,2000)) , (' SQL Text Not Available ')) SqlText
from
(
select sql_id,max(module) module,sum(elapsed_time_delta) elap,sum(cpu_time_delta) cput,sum(executions_delta) exec,
to_char(min(ss.BEGIN_INTERVAL_TIME),'yyyy-mm-dd hh24:mi:ss') as begin_time,
to_char(max(ss.END_INTERVAL_TIME),'yyyy-mm-dd hh24:mi:ss') as end_time
from dba_hist_sqlstat s , DBA_HIST_SNAPSHOT ss
where s.dbid = 1766956972 and s.instance_number = 1
and ss.snap_id = s.snap_id and ss.instance_number = s.instance_number
and &beg_snap < s.snap_id and s.snap_id <= &end_snap
group by s.sql_id
) sqt,dba_hist_sqltext st where st.sql_id(+) = sqt.sql_id and st.dbid(+) = 1766956972
order by nvl(sqt.elap, -1) desc,sqt.sql_id
)
where rownum < 65 and (rownum <= 15 or norm_val > 1);
网友评论