1.查詢sql執行最慢的語句
select * from (select a.sql_text,a.sql_fulltext,a.executions "執行次數",round(a.elapsed_time / 1000000,2) "總執行時間", round(a.elapsed_time / 1000000 / a.executions,2) "平均時間",a.command_type,a.parsing_user_id "用戶ID",b.username "用戶",a.hash_value from v$sqlarea a left join all_users b on a.parsing_user_id=b.user_id where a.executions>0 order by (a.ELAPSED_TIME / a.executions) desc) where rownum<=50;
2.執行次數最多的sql語句
select * from (select a.sql_text,a.executions "執行次數",a.parsing_user_id "用戶",rank() over(order by a.executions desc) exec_rank from v$sql a left join all_users b on a.PARSING_USER_ID=b.user_id) c where exec_rank<=100;