forked from khailey-zz/ashmasters
-
Notifications
You must be signed in to change notification settings - Fork 1
/
topsql.sql
36 lines (36 loc) · 1.13 KB
/
topsql.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
select * from (
select sql_id, round(w*100,2) pct,
nvl("'ON CPU'",0) "CPU",
nvl("'Scheduler'",0) Scheduler ,
nvl("'User I/O'",0) "User I/O" ,
nvl("'System I/O'",0) "System I/O" ,
nvl("'Concurrency'",0) Concurrency ,
nvl("'Application'",0) Application ,
nvl("'Commit'",0) Commit,
nvl("'Configuration'",0) Configuration,
nvl("'Administrative'",0) Administrative ,
nvl("'Network'",0) Network ,
nvl("'Queueing'",0) Queueing ,
nvl("'Cluster'",0) "Cluster",
nvl("'Other'",0) Other
from (
select sql_id,
decode(session_state,'WAITING',wait_class,'ON CPU') wait_class,
sum(count(*)) over (partition by sql_id) / sum(count(*)) over () w,
count(*) cnt,
sum(count(*)) over () totalsum
from v$active_session_history
where sample_time > sysdate - &NUM_MIN/24/60
group by sql_id,
decode(session_state,'WAITING',wait_class,'ON CPU')
order by sql_id
)
pivot (
sum(round(cnt/totalsum*100,2))
for (wait_class) in
('Administrative','Application','Cluster','Commit','Concurrency',
'Configuration','Network','Other','Queueing','Scheduler','System I/O',
'User I/O','ON CPU'
)
) where sql_id is not null order by 2 desc
) where rownum < 10;