I am getting some issue when running sql from sqlplus and want to assign the o/p to a Unix variable.The Output is showing correct in log file but not assign to variable. code :
PASSWD variable conatins user/password/DB details.
STATUS=`sqlplus -s /nolog <<EOF>> /home/test_db.log
CONNECT ${PASSWD}
WHENEVER OSERROR EXIT FAILURE
WHENEVER SQLERROR EXIT SQL.SQLCODE
set termout off
set showmode off
set heading off
set echo off
set timing off
set time off
set feedback 0
set pagesize 0
set embedded ON
set verify OFF
select status from int_control_tab where rec_no=877 and process_date=to_date('15/02/2017','dd/mm/yyyy');
exit;
EOF`
echo "STATUS :" ${STATUS}
Even i am getting o/p i.e 1 value in log file but not assigning value to STATUS variable. Please suggest.
/home/test_db.log. If you want it in the variable as well, use|tee -a /home/test_db.loginstead of>>/home/test_db.log. If you want the exit status. It's in$?. And remember to quote your variables!