How to fetch data from oracle in unix shell script

Hi,

How to fetch data from oracle database in unix shell scripting.

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:

list=`abcd','6u290','koekw'

Can anyone please help me out...

Thanks,
Anusha

We cannot see what you got to start with.

Please show what you got that is not right.

Hi,

The output i am getting is below:

list=356 677 899 123 567 123 098 128

But I need output like this:

list='356','677',6780','900'

So can you suggest how to get output like this.

Thanks,
Anu

Hi,

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

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

Regards,
Birei

list=$(printf "'%s'," $list)
echo "${list%,}"