If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > how to use SPOOL in a stored Procedure?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-25-03, 04:27
Sreekanth Vanam Sreekanth Vanam is offline
Registered User
 
Join Date: Jul 2003
Posts: 5
how to use SPOOL in a stored Procedure?

How can I use SPOOL Command in a stored procedure to divert the output of a select statement to a file?
Reply With Quote
  #2 (permalink)  
Old 11-25-03, 05:59
andrewst andrewst is offline
Moderator.
 
Join Date: Sep 2002
Location: UK
Posts: 5,171
Re: how to use SPOOL in a stored Procedure?

You can't. You could use UTL_FILE to write to a file on the server. Or, if there is not too much output, you could use DBMS_OUTPUT in the stored procedure and SET SERVEROUT ON in SQL Plus before running it.
__________________
Tony Andrews
http://tinyurl.com/tonyandrews
Reply With Quote
  #3 (permalink)  
Old 04-22-04, 03:55
amit_krai amit_krai is offline
Registered User
 
Join Date: Apr 2004
Posts: 2
Re: how to use SPOOL in a stored Procedure?

Quote:
Originally posted by andrewst
You can't. You could use UTL_FILE to write to a file on the server. Or, if there is not too much output, you could use DBMS_OUTPUT in the stored procedure and SET SERVEROUT ON in SQL Plus before running it.
Sorry dear friend by using ref cursor it's possible.
Reply With Quote
  #4 (permalink)  
Old 04-22-04, 07:20
andrewst andrewst is offline
Moderator.
 
Join Date: Sep 2002
Location: UK
Posts: 5,171
Re: how to use SPOOL in a stored Procedure?

Quote:
Originally posted by amit_krai
Sorry dear friend by using ref cursor it's possible.
You think so? OK, if you can make the SQL Plus "SPOOL" command work from a stored procedure using a REF CURSOR, please share your code!
__________________
Tony Andrews
http://tinyurl.com/tonyandrews
Reply With Quote
  #5 (permalink)  
Old 04-22-04, 08:57
padderz padderz is offline
Registered User
 
Join Date: Aug 2001
Posts: 66
Well if you mean something like this...
Code:
Oracle9i Enterprise Edition Release 9.2.0.4.0 - 64bit Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.4.0 - Production

SQL> CREATE OR REPLACE PROCEDURE procedure_name (
  2    column_name IN VARCHAR2,
  3    ref_cursor OUT SYS_REFCURSOR)
  4  IS
  5  BEGIN
  6    OPEN ref_cursor FOR 
  7      ' SELECT SUM (sal), ' || column_name || 
  8      ' FROM emp GROUP BY ' || column_name; 
  9  END;
 10  /

Procedure created.

SQL> SET AUTOPRINT ON;
SQL> VARIABLE ref_cursor REFCURSOR;
SQL> SPOOL emp_groups.lst
SQL> EXEC procedure_name ('DEPTNO', :ref_cursor);

PL/SQL procedure successfully completed.


  SUM(SAL)     DEPTNO
---------- ----------
      8750         10
     10875         20
      9400         30

SQL>
...then that is not calling SPOOL from a PL/SQL procedure - the stored procedure has finished executing, the output is being SPOOLed by SQL*Plus, not by PL/SQL. Perhaps we are splitting hairs - can the original poster confirm whether this is what they meant?

Padders
__________________
Padderz
SYSOP, Quest Software / RevealNet Labs PL/SQL Pipeline
Reply With Quote
  #6 (permalink)  
Old 05-14-04, 04:50
amit_krai amit_krai is offline
Registered User
 
Join Date: Apr 2004
Posts: 2
Spool File

For Spooling, create a batch file and call it into your procedure.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On