Linux: Returning a SQL value into a variable


Problem

You want to populate a variable from SQL.

Solution


RETVAL=`sqlplus -silent $v_sqllogin  << EOF
set PAGESIZE 0 FEEDBACK OFF VERIFY OFF HEADING OFF ECHO OFF
select count(*) from abc_def where release_id = $v_release_name and status = 'I';
exit;
EOF`


Note:

You will want trim the spaces from the output.
http://barrybrierley.blogspot.com/2016/07/linux-trimming-spaces-from-variables.html

Comments