How to fetch data from oracle in unix shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to fetch data from oracle in unix shell script
# 1  
Old 11-25-2010
How to fetch data from oracle in unix shell script

Hi,

How to fetch data from oracle database in unix shell scripting.
Code:
list=`sqlplus -s ds_user/dsuser@EMI <<EOF
set feedback off
set serveroutput on
set heading off
set pagesize 0
set tab off
select IP_ID from  table
/
exit
EOF`

The output is not what i expected.I need output in the following format:
Code:
list=`abcd','6u290','koekw'

Can anyone please help me out...


Thanks,
Anusha

Last edited by Scott; 11-27-2010 at 06:54 AM.. Reason: Code tags
# 2  
Old 11-26-2010
We cannot see what you got to start with.

Please show what you got that is not right.
# 3  
Old 11-26-2010
Hi,

The output i am getting is below:
Code:
list=356 677 899 123 567 123 098 128

But I need output like this:
Code:
list='356','677',6780','900'

So can you suggest how to get output like this.

Thanks,
Anu

Last edited by Scott; 11-27-2010 at 06:54 AM.. Reason: Code tags
# 4  
Old 11-26-2010
Hi,

No idea about sqlplus but try using 'sed' after the sql instruction.

Code:
echo $list | sed "s/\([0-9]\+\)/\'\1\'/g; s/^ *//; s/ *$//; s/ \+/,/g"

Regards,
Birei
# 5  
Old 11-26-2010
Code:
list=$(printf "'%s'," $list)
echo "${list%,}"

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Fetch Data from File using UNIX or Perl

Hello, How All are Doing today. I have a issue, I have a file which contains the data as follow <ENVELOPE><ENVELOPE_ID>TEST</ENVELOPE_ID><ENVELOPE_EXTERNAL_ID></ENVELOPE_EXTERNAL_ID><ENVELOPE_VERSION>2</ENVELOPE_VERSION><SIResourceDefaultVersion>true</SIResourceDefaultVersion><TYPE>GS... (1 Reply)
Discussion started by: adisky123
1 Replies

2. UNIX for Dummies Questions & Answers

how to fetch data in unix

Hi All, I have a file with the below data as shown. A|2|20120430 B|EMP|NAME|DEPT C|12|SARC|01 C|23||ASDD|02 D|END OF FILE I want to fetch only the records that contains C|, what is unix command to fetch this data. Thanks (5 Replies)
Discussion started by: halpavan2
5 Replies

3. Shell Programming and Scripting

Script to fetch data from HTML

Hi All, There is a link from were I usually search somthing and fetch the data from. Is there any way to automate it through a script if I mention search criteria in a note pad. I mean the script to search the content on the notepad and resutls should be placed into another file. ... (2 Replies)
Discussion started by: indradev
2 Replies

4. Shell Programming and Scripting

why do we need UNIX shell script to load data into Oracle database

Hello everyone, I am new to shell scripting/ loading data into a database. I want to load data into Oracle database using SQL loader. Can some one please explain why do we need unix shell script to load the data into the database? Also can someone please explain what has to be in that script?... (5 Replies)
Discussion started by: new_prog
5 Replies

5. Shell Programming and Scripting

Shell script to export data from Oracle table .

Hi, I want to write a shell script which will export data from oracle table . I don't want to save that data . I want the queries . Right now i am right clicking on the table and clicking on export as to my desktop . Please let me know if any one have any idea . (2 Replies)
Discussion started by: honey26
2 Replies

6. Shell Programming and Scripting

Need shell script to extract data from oracle database

shell script (4 Replies)
Discussion started by: frns5
4 Replies

7. Shell Programming and Scripting

How to fetch data from a text file in Unix

I want to fetch passwords from a common file xxxx.txt and use it in a script. Currently the password is hardcoded so this have to be changed so that password can be fetched from text file..... Please reply asap.. Thanks (4 Replies)
Discussion started by: shikhakaul
4 Replies

8. Shell Programming and Scripting

Need Shell Script to upload data from Text file to Oracle database

Hi Does any one have any idea on uploading the data using Unix Shell script from text file to Oracle database. Requirement:- 1. Need to connect to Oracle database from Unix Shell script. 2. Need to pick Text file from some location on Unix Box. 3. Need to upload the data from text file to... (6 Replies)
Discussion started by: chandrashekharj
6 Replies

9. Shell Programming and Scripting

Shell Script for Data loading in Oracle

Hi All I am new to unix. I need a shell script to load a datafile in to oracle. I already have a control file, and data file. all I need is if i execute the shell it must load the data using the ctl file to table. Control file : PAY0001.ctl Datafile : mon_grs_det.dat log file :... (3 Replies)
Discussion started by: raghuraja_r
3 Replies

10. Shell Programming and Scripting

unix script to export data from csv file to oracle database

Hello people, Need favour. The problem I have is that, I need to develop a unix shell script that performs recurring exports of data from a csv file to an oracle database. Basically, the csv file contains just the first name and last name will be dumped to an Unix server. The data from these... (3 Replies)
Discussion started by: vinayagan
3 Replies
Login or Register to Ask a Question