Link to home
Start Free TrialLog in
Avatar of HabBoy
HabBoy

asked on

retrieving data from oracle to flat file

Hi,

I am new to unix and would like to write a script that would allow me to extract 2 fields from an oracle database and write them out to a flat file.
Could someone point me in the right direction.

Thanks
ASKER CERTIFIED SOLUTION
Avatar of bira
bira

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of hakula
hakula

You may use SQL*Plus concatenation "||". You'd better set feedback off also.

#!/bin/sh
sqlplus scott/tiger 2>/dev/null <<EOC
set heading off feed off term off

spool flat.txt
select ename || '|' || job || '|'
from emp;
spool off
quit
EOC

# flat.txt lists ename and job, delimited by "|".
# Each line is terminated by "|". You may
# use Unix utilities such as sed, awk to process it

Regards.
Avatar of HabBoy

ASKER

Thanks bira.

Habboy