Placing a SQLPlus script in a UNIX shell Wrapper

posted Feb 4, 2012, 3:01 PM by Sachchida Ojha   [ updated Feb 4, 2012, 3:11 PM ]
We will use  a simple select statement in a UNIX shell wrapper in our example.

#!/bin/bash

#Set the env
ORACLE_SID=testdb
export ORACLE_SID
export ORATAB=/etc/oratab
export ORACLE_HOME=`grep "$ORACLE_SID" $ORATAB | awk -F: '{print $2}'`
PATH=$ORACLE_HOME/bin:$PATH
export PATH
$ORACLE_HOME/bin/sqlplus dbaref/dbaref<<!

SELECT * from v\$database;
@/home/oracle/DBA/scripts/test.sql
exit
!


You can also run the sql script

$sqlplus dbaref/dbaref @/home/oracle/DBA/scripts/test.sql


Comments