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!

How to spool data from a table into separate text files?

638257Jul 22 2008 — edited Jul 23 2008
Hi,

Slight change in the question...

I have a table in my oracle database and I want to spool the data into text files splitting it by a column eg
ORACLE SQL TABLE: Country_data

3 columns of data in table
Country_id name age
123 Harshad 25
123 Deepak 21
456 Anil 22
456 Anand 15
789 Swamy 22
789 Santosh 35

I want to create in this example 3 text files and split the data in the text files by country_id eg this would work:

spool C:\123.txt
select Country_id, name, age
from country_data
where country_id='123'
;
spool off
;

spool C:\456.txt
select Country_id, name, age
from country_data
where country_id='456'
;
spool off
;

spool C:\789.txt
select Country_id, name, age
from country_data
where country_id='789'
;
spool off
;

But I can't hardcode the country_id's as they change. Is there a way with SQL or PL SQL to search the table, get the country_id's then say spool the data into a file, country_wise. Also creating the text file with the filenames eg 123.txt, 456.txt, 789.txt etc.

Thanks,
Harshad

Message was edited by:
Harshad
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 20 2008
Added on Jul 22 2008
8 comments
1,924 views