I have a question about spooling the the results of my program. My sample sql script looks like this.
whenever sqlerror exit failure rollback
set heading off
set arraysize 1
set newpage 0
set pages 0
set feedback off
set echo off
set verify off
declare
ab varchar2(10) := 'Raj';
cd varchar2(10);
a number := 10;
c number;
d number;
begin
c := a+10;
select ab,c into cd,d from dual;
end;
SPOOL
select cd,d from dual;
SPOOL OFF
EXIT;
The above script does not work, but I want to do something like this where in the begin end block we compute some values and i want to spool those results.
Thanks.
With spool:
In order to execute a spool file in plsql Go to File->New->command window -> paste your code-> execute. Got to the directory and u will find the file.
This will spool the output from the anonymous block into a file called
output_<YYYYMMDD>.txt
located in the root of the local PC C: drive where<YYYYMMDD>
is the current date:Hope it helps...
EDIT:
After your comment to output a value for every iteration of a cursor (I realise each value will be the same in this example but you should get the gist of what i'm doing):
To spool from a
BEGIN
END
block is pretty simple. For example if you need to spool result from two tables into a file, then just use thefor loop
. Sample code is given below.