当前位置: 代码迷 >> Oracle开发 >> spool脚本里想打印出PL里执行SQL结果解决方法
  详细解决方案

spool脚本里想打印出PL里执行SQL结果解决方法

热度:82   发布时间:2016-04-24 06:47:22.0
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                                                                                                                                                                                        


PL/SQL 过程已成功完成。



虽然用了execute immediate sql1;但select的结果并没打到1.txt里,怎么才能将结果打出来呢?

------解决方案--------------------

感觉再加一层spool
  相关解决方案