This may be a stupid idea. I am trying to write a SQL*Plus .sql script that I can call from a Windows batch file that itself generates a new .sql script using dbms_output.put_line. This is what I have so far for my script:
set echo off;
set serverout on;
conn user@pass;
spool E:\new_script.sql
DECLARE
CURSOR c_groups IS
SELECT * FROM table;
s varchar2(4000);
BEGIN
dbms_output.put_line('BEGIN');
FOR x IN c_groups LOOP
s := 'INSERT INTO TABLE blah VALUES ('''||x.name||''','||x.id||');';
END LOOP;
dbms_output.put_line(s);
dbms_output.put_line('COMMIT;');
dbms_output.put_line('END;');
dbms_output.put_line('/');
END;
/
spool off;
exit;
However, when I do this, my new_script.sql
just says "PL/SQL procedure successfully completed." Any ideas how to make the dbms_out.put_line
actually display their message?
And I'm not actually doing this to build insert statements - those are just a simple sample showing the gist of what I'm trying to do.
SPOOL
sends the results to a file; but it doesn't ensure that results are printed. To enable the printing to stdout; use theSERVEROUTPUT
command.This is generally a poor way of going about things; I recognise that you said this wasn't what you're actually doing but SQL is a set based language. Do things in bulk if at all possible.