Solved

retrieving data from oracle to flat file

Posted on 2001-08-22
3
292 Views
Last Modified: 2010-04-21
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
0
Comment
Question by:HabBoy
3 Comments
 
LVL 6

Accepted Solution

by:
bira earned 100 total points
ID: 6414680
Hi
  A little example here:

sqlplus user/password  <<fim
SET HEADING OFF
spool flat.txt
select tablespace_name from user_tablespaces ;
spool off
fim


  Save the above script, chmod it 777 and run it as
an oracle user.

   This will create the file named flat.txt  with the
result of the select.

     Regards
0
 
LVL 1

Expert Comment

by:hakula
ID: 6458487
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.
0
 

Author Comment

by:HabBoy
ID: 6480539
Thanks bira.

Habboy
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now