Tuesday, December 11, 2007

Data extraction from oracle to csv file

First of all we have to create a script (test.sql) to extract our data:

spool test.csv
set colsep ";"
set pagesize 0
set linesize 10000

SELECT A, B, C
FROM TB_AA
INNER JOIN TB_BB
ON TB_BB.ID = TB_AA.EXT_ID
WHERE TB_AA.FOO = 4;

spool off
exit

Once this is done we can use this command to run the script we have just created:

$ sqlplus user/passwor@ @test.sql

At this point we will obtain as result a file (test.csv) in our folder.

No comments: