Tag Archives: PRODUCT

Problems with fetching data from Oracle database

By kumarjt

Here’s a database query which looks up the NAME column of PRODUCT table


SELECT NAME FROM PRODUCT ;


And this query retrieves me the following output
SUGAR
COCOA
HONEY
WHEAT
CABBAGE
CAULI FLOWER
[6 rows selected]
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

Thanks
Kumarjit.

…read more
Source: FULL ARTICLE at The UNIX and Linux Forums