实际工作中,经常需要跑一些SQL脚本,并且需要跟踪该脚本的日志,此处总结了一下如何更改该脚本让其自动写日志:
/**********************************************************/
/**Add this at the head of the script to trace the script**/
spool D:\dba\MF_bcc_purge\bcc_purge.log
alter session set sql_trace=true;
SELECT 'TKPROF ' ||tracefile||' '||tracefile||'.out' as TRACEFILE FROM v$process WHERE addr IN (SELECT paddr FROM v$session WHERE sid IN (SELECT sid FROM v$mystat WHERE ROWNUM = 1));
set timing on
set echo on
/**********************************************************/
--here is the concept of the script.
/**********************************************************/
set echo off
/**Add this at the end of the script to trace the script**/
alter session set sql_trace=false;
spool off
/**********************************************************/