How to store the sql query's output in a variable

Hi,

My requirement is :
We are calling an sql statement from a UNIX session, and fetching data into some variables from a table .. now we are unable to access these variables from outside the SQL part. Please let me know how can I achieve this.

Can you please share a code snippet which elucidates this.

Thanks & Regards,
Venkatesh.

Generally it can be :

sqlresult="mysql -defaults-file=/opt/mysql.conf -ppassword DB -e SELECT * FROM TABLE;"

and then play with $sqlresult varaible.

#!/bin/ksh
result=$(echo 'SELECT * FROM TABLE' | mysql DB)

from pl/sql you can do something like this, i'm not sure if will work with non numeric values [ but you can try ] i use this to pass exit status if sql failed.

sample.sql

variable status number;
declare
status number;
begin
:status:=2;
end;
/
column status new_value status noprint
select :status status from dual;
exit &status

Regards
Peter

Hi All,

     Thanks alot for the quick help, I will test them and revert incase i face any issues. 

Regards,
Venkatesh.:slight_smile: