Please note the last record CAULI FLOWER contains TWO blank spaces between the two words.
Now I want to do the same using Unix script and I wrote the following :
set -A prod_list `sqlplus -s USER/PWD@DB <<!
SET HEADING OFF ;
SET NEWPAGE NONE ;
SET FEEDBACK OFF ;
SET LINESIZE 4000 ;
SET WRAP OFF ;
SELECT NAME FROM PRODUCT ;
!
`
and then queried the prod_list array to find 7 instead of 6 entries
for product in ${prod_list[@]} ; do
echo $product
done
The output is like
SUGAR
COCOA
HONEY
WHEAT
CABBAGE
CAULI
FLOWER
7 items in the array.
My guess is the TWO interim spaces within the last record value is splitting the record in two seperate records
at that point of time when I am trying to fetch the records via sqlplus (ie., via Unix).
Can this behavior be overridden ? If yes how ?
Also we tried to use a SQL cursor to fetch the values into unix , but we do not know exactly how to do it.
Can anybody help us on that too ?
Please note :
Unix version : Korn Shell
OS : Linux
Database : Oracle 11g
There are four single quotes at the beginning and end of the field you are requesting along with double pipe marks to concatenate. This should return you quoted values that I hope will load your array.
I regret I don't have anything I can test this on though, so can you give it a try and let us all know how you get on.
Its a mixed experience , as the solution from rbatte1 wasnt fruitful enough but bipinajith 's clicked good time.
And for that I would like to thank you both for chipping in with your feedbacks , irrespective of the yield.
I am just stuck at some other place that i might seek your help to pass by.
The SPOOL command
spool prod_list.txt
SELECT NAME FROM PRODUCT ;
spool off;
not only writes all the data outcome into the file but also displays the output in the Unix command line , and I must not show to the user any output from the database.