handling Multiline SQL outputs

Hi,

I'm using KSH and calling a SQL statement inside my script which returns more than 1 record.

Result=`sqlplus -s $DB_USER/$DB_PWD@$DB_STRING <<END
set echo off
set head off
spool junk.txt
select Name from abc where job = 'Manager';
spool off
exit;
END`

echo $Result

The above SQL returns 3 names as:

But when i'm calling this SQL in my script and assigning the Result to a variable "Result" and echoing the same, the result comes out in a single line like below:

What I require is the output should be assigned to the variable result in the below format so that I can seggregate the records:

Is there any way i can achieve such result?

Thanks in advance.

OIFS="$IFS"
IFS=' '
#your code here
#
#
IFS="$OIFS"

Hi,

It doesnt work ... i didnt get the meaning of IFS and OIFS? what are they? are these variables? what is the use of these variables?

Please explain?

Thanks.

Sorry Admin ... my mistake .. it really works ... :b:

Can u explain a little bit on how u achieved it? Is there any documentation for OIFS and IFS?

OIFS is just a variable I used to hold IFS while it is changed so I can set it back afterwards, since I don't know if it will be the default or not.

# cat test
1
2
3
4
5 6
# OIFS="$IFS"
# a=$(cat test)
# echo $a
1 2 3 4 5 6
# IFS=' '
# echo $a
1 
2 
3 
4 
5 6
# IFS="$OIFS"
# echo $a
1
2
3
4
5
6

Thanks a lot !!

Nice explaination !!! You made my day ! :slight_smile: