Spooling multiple files

馋奶兔 提交于 2021-02-19 06:58:22

问题


I have a report that I need to export to a csv file for n number of vendors. i have a feeling that I will need to run this more than once so I would like to automate it as much as possible. I wrote the sql plus needed to for one vendor, I'm wonder how can script it to run for each vendor. I have the vendor list stored in the table in the db, but knowing I can't put spool in an pl/sql block, I'm wonder how I can loop through each vendor to create their file.


回答1:


I've done similar things by having one script generate a secondary script and then execute that script. Approximate example:

set serveroutput on
set termout off
spool temp_script.sql
Begin
    for r in (select * from vendors) loop
        dbms_output.put_line('spool '||r.vendor_name||'.csv');
        dbms_output.put_line('data is: '||r.data);
        /*feel free to put other output commands here */
        dbms_output.put_line('spool off');
    end loop;
end;
spool off
@temp_script.sql


来源:https://stackoverflow.com/questions/4148458/spooling-multiple-files

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!