Solved getting result of SQL query into Korn

March 20, 2012 at 07:24:01
Specs: Red Hat Linux, unk remote server
I need to run a query in sqlplus in korn on a Red Hat Linux box and use the results to populate a korn variable. Like this:

sqlplus (wallet)
SQL> select count(*) from error_table;

Then, if the count is zero I want to populate $Flag1 to 0, otherwise $Flag1 becomes 1. After running several of these queries, my ksh script will decide to exit 1 or 0 depending on the values.

I'm able to make the sql connection and run the query, but don't know how to get the results back into the ksh program flow.


See More: getting result of SQL query into Korn

Report •


#1
March 20, 2012 at 09:40:49
✔ Best Answer
In ksh, use command substitution $( ) to trap the output of a command:

#UNTESTED!
my_value=$($ORACLE_HOME/bin/sqlpus -S <login stuff> << EOF
SET HEADING OFF
SET PAGESIZE 0
REPFOOTER OFF
select count(*) from error_table;
exit
EOF)
# end script

In the above example, I am using a Linux here document - execute sqlplus beteween here: << EOF

and here:
EOF

Note the Oracle set values I am using to limit output; yours may be different.


Report •

#2
March 20, 2012 at 11:50:50
Thank you!

Report •
Related Solutions


Ask Question