I am trying to call a SQL*Plus (10g) script from a Korn shell script.
I'm not allowed to modify the SQL*Plus script, and it has a SQL*Plus ACCEPT command in it.
I'm trying to pass my specific argument for this ACCEPT-command variable (7788 further below) in to the SQL*Plus script via the Korn Shell script.
Here is a whittled-down version of the SQL*Plus script, oracle_code.sql:
SET VERIFY OFF
ACCEPT abc PROMPT "Enter an empno:"
SELECT e.ename
FROM emp e
WHERE TO_CHAR(e.empno) = '&abc'
;
And here is my attempt at the Korn shell script (wrapping_shell_script.sh) to make the call:
#!/usr/bin/ksh
# wrapping_shell_script.sh
# Expecting one and exactly one parameter to be passed, the password for SCOTT
if [ $# -ne 1 ]
then
echo "USAGE: wrapping_shell_script.sh <SCOTT_Password>"
exit 1
fi
passwd="$1"
echo `date`
sqlplus -s scott/${passwd} @oracle_code.sql << EOF1
7788
EOF1
Here's what it looks like when I run the shell script from the Korn shell command line:
$ wrapping_shell_script.sh tiger
Fri Oct 31 16:23:20 CDT 2014
Enter an empno:
no rows selected
$
The 7788 value I'm trying to pass isn't making its way into the SQL*Plus script's abc lexical parameter.
How can I change my Korn shell script such that the value I'm specifying is passed in, and the invoked SQL*Plus script executes?
Thanks.
echo 7788 | sqlplus ...? Good luck.[oracle@dbsgoel1 gvenzl]$ ./wrapping_shell_script.sh tiger Mon Nov 3 10:50:00 GMT 2014 Enter an empno: ENAME ---------- SCOTTWith verify on:[oracle@dbsgoel1 gvenzl]$ ./wrapping_shell_script.sh tiger Mon Nov 3 10:50:27 GMT 2014 Enter an empno:old 3: WHERE TO_CHAR(e.empno) = '&abc' new 3: WHERE TO_CHAR(e.empno) = '7788' ENAME ---------- SCOTT