我需要按顺序为查询集生成report_sql_monitor,并将其转换为文件。 所以我有以下内容:
Test.sql / 以下是更正后的版本:
set pagesize 1000
set echo off
set feedback on
set timing on
set autotrace on stat
define file=./output.txt
define file
col prev_sql_id new_value SQLID --get the SQL_ID of previous query to put it further into report_sql_monitor
select /*+ Monitor */ name, last_name from family --first query
/
select prev_id from v$session where sid = sys_context('USERENV','SID') --get SQL_ID
/
spool &file
select dbms_sqltune.report_sql_monitor(
sql_id => '&SQLID',
type = > 'TEXT',
report_level => 'ALL') as report from dual --Report was generated
/
spool off --close spooling
--the second query
select /*+ Monitor */ salary,month from salary
/
select prev_sql_id from v$session where sid =sys_context('USERENV','SID') --get SQL_ID
/
spool &file append
select dbms_sqltune.report_sql_monitor(
sql_id => '&SQLID',
type = > 'TEXT',
report_level => 'ALL') as report from dual -- REPORT IS NOT GENERATED
/
spool off
问题是上面的test.sql只为第一个带有'statistics'的查询生成report_sql_monitor报告。生成的文件(output.txt)应具有以下内容:
统计
xx recursive call
xx db block gets
xx consistent gets
xx physical reads
and so forth