Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

spool inside a loop

575823May 21 2007 — edited May 22 2007
Is it possible to use the spool statement inside a loop? I am trying to create three separate files each containing a million record. Using spool on its own works but when nested inside a loop gives me errors.

declare
v_rn_start_1 NUMBER:=1;
v_rn_end_1 NUMBER:=1000000;
v_rn_start_2 NUMBER:= 1000000;
v_rn_end_2 NUMBER:=2000000;
v_rn_start_3 NUMBER:=2000000;
v_rn_end_3 NUMBER:=3000000;
begin
for i in 1..3 loop
SPOOL on
Set Heading off
set echo off
set feedback off
set linesize 150
set trimspool on
SPOOL C:\output_i.txt
select addr
from (
select rownum rn, mbr_no||',"'||mbr_res_unit_no||'","'||mbr_res_street_no||'","'||mbr_res_street||'","'||mbr_res_town||'","'||mbr_res_state||'",'||mbr_res_pcode as Addr
from IT.MEMBER
where trim(mbr_close_yyyy) = 0
and mbr_res_pcode > 0
)
where rn >= v_rn_start_i and rn < v_rn_end_i;
SPOOL off
end loop;
end;
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 19 2007
Added on May 21 2007
6 comments
11,660 views