Solved

retrieving data from oracle to flat file

Posted on 2001-08-22
3
302 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
AIX Server 10 87
Java core in Solaris 10 1 295
text in table need to be center of the box 4 81
aix tls version 6 417
In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
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.

839 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