日期:2014-05-17  浏览次数:21118 次

spool脚本里想打印出PL里执行SQL结果
spool1.sql:

var v1 number;
exec select max(TASK_ID) into :v1 from SQL_RESULT;
var v2 number;
exec select count(distinct FILENAME) into :v2 from SQL_TIME where TASKID = :v1 ;

spool d:\1.txt
select taskid ,taskname from test_task where taskid=:v1;

declare
sql1 varchar2(512);
begin
for i in 1..:v2 loop
sql1 :='select INSQLID "文件内SQL编号",sum(SQLTIME) "Time(ms)" from SQL_TIME where TASKID = '||:v1||' and FILENAME=''./result/SQL'||i||'.format'' group by rollup(INSQLID) order by INSQLID';
dbms_output.put_line('SQL文件'||i);
dbms_output.put_line(sql1);
execute immediate sql1;
end loop;
end;
/

spool off

spool的结果1.txt,如下:

    TASKID TASKNAME                                                                                                                                                                                     
---------- ----------------------------------------------------------------                                                                                                                             
        19 SSB1S