Click to See Complete Forum and Search --> : running SQL plus from UNIX


que_card
07-12-2002, 10:54 AM
What I want to do is return the value from my query back to the calling UNIX ksh program.

I run the command from my ksh script
> runsql.ksh

echo "Script starting"

sqlplus ${OP_CONNECT_STRING}@${OP_ORA_INST} @sqls/sel_logical_dt.sql

echo $date

echo "Script ending"

>

In my sel_logical_dt.sql file I have

select date from logical_date;

I want to return this date back to the calling unix progam for display.

bensr
07-15-2002, 06:23 AM
Try something like this:
sqlplus ${OP_CONNECT_STRING}@${OP_ORA_INST} @sqls/sel_logical_dt.sql > logical_dt.log

rc=$?

if [ $rc -eq 0 ]
then
ANSWER=`cat logical_dt.log`
else
# In this case there will be an error
ANSWER=""
fi
echo $ANSWER

==============================
Don't forget in your sql:
set heading off
set pagesize 0
set feedback off
set verify off
set termout off
set timing off
set wrap on
WHENEVER SQLERROR EXIT SQL.SQLCODE

==============================
Without error-detection:
ANSWER=`sqlplus ${OP_CONNECT_STRING}@${OP_ORA_INST} @sqls/sel_logical_dt.sql`

pando
07-15-2002, 06:52 AM
codejecucionproceso=`sqlplus -s << KOF
${METAUSER}/${METAPWD}@${METATNS}
@$METASQL/insert_metadatos.sql "$1" "$2" "$3" "$4"
exit 0;
KOF`

echo $codejecucionproceso

que_card
07-17-2002, 04:36 PM
That worked fine... The only problem with redirection is that the output file contains the verbiage when you connect and exit from oracle. However, I used the AWK command to strip out what I needed.

Thanks,

Que_card