Reputation: 62
how to execute sql query or script using sqlplus as the middle man and insert output to bash variable?
Upvotes: 0
Views: 1458
Reputation: 62
nothing worked for me of the (at least) 3 good looking stack-overflow and other websites tutorials so I'm posting what worked for me, for the of chance that it will be useful to some one else.
the code:
#!/bin/bash
export ORACLE_SID=<DB_SID>
VAL=""
VAL=`sqlplus -s / as sysdba << EOF
whenever sqlerror exit sql.sqlcode;
set echo off
set heading off
@<sql_script_path>
exit;
EOF`
echo $VAL
Upvotes: 1