Solved

retrieving data from oracle to flat file

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

895 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

13 Experts available now in Live!

Get 1:1 Help Now