1

Hy Guys, I don't understand how to create a correct script for spool, of multiple files. I have read some question about this problem, but I was unable to solve it.

this is my code MAIN_PROCEDURE.sql

SET serveroutput ON;
SET trimspool ON;
SET pagesize;

PROCEDURE DINAMIC_SPOOL(file_name VARCHAR2) IS
BEGIN
 dbms_output.put_line('spool '|| file_name || '.txt');
 dbms_output.put_line('bla bla bla');
 dbms_output.put_line('spool off');

END DINAMIC_SPOOL;


BEGIN
 file_name:='test_1';
 DINAMIC_SPOOL(file_name);

 file_name:='test2';
 DINAMIC_SPOOL(file_name);

END;
/
EXIT;

Otherwise, there is another method? I hope in your kind reply.

wolφi
  • 8,091
  • 2
  • 35
  • 64

2 Answers2

2

PL/SQL procedures live on the database server. You write procedures and packages which access the database and can - with some effort, for instance with the package UTL_FILE- write files on the database server.

SQL*Plus lives on the client. It can access the database and spool the output of queries to files on the client. However, it is not a full scripting language, there are no loops, no if/then, no procedures, just plain SQL in in SQL*Plus.

So to speak, SQL*Plus is SQL plus some formatting/spooling extras, and PL/SQL is the (P)rocedural (L)anguage for (SQL).

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
wolφi
  • 8,091
  • 2
  • 35
  • 64
1

I don't think that what you try do can work.

SPOOL is a SQLPlus command and as such can only be executed directly by SQLPlus.

DBMS_OUTPUT a PL/SQL package that runs on the server: its output is retrieved by SQLPlus and displayed by SQLPlus but it does run on the database server side: and it cannot run SQLPlus commands.

pifor
  • 7,419
  • 2
  • 8
  • 16