问题
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