How to spool data from a table into separate text files?
638257Jul 22 2008 — edited Jul 23 2008Hi,
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