Skip to Main Content

Oracle Database Discussions

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

querying column values and storing them in variables in a shell script

913195Jul 15 2013 — edited Jul 15 2013

wtDear All,

I have written a bash shell script to call sqlplus , querying a table in oracle schema to fetch values from

two columns of this table.

Here is the scrpt.

#!/bin/bash

ORACLE_HOME=/opt/oracle/client/11.2.0.3

export ORACLE_HOME

PATH=$ORACLE_HOME/bin:$PATH

export PATH

LD_LIBRARY_PATH=$ORA_HOME/lib:$LD_LIBRARY_PATH

export LD_LIBRARY_PATH

v_JobName='DefaultJob'

v_JobStatus='DefaultStatus'

sql=`sqlplus -s power_center/Nn65xcxj@siebdev <<SQL_END

set head off

select job_name, job_status into :v_JobName, :v_JobStatus  from audit_control_table;

/

SQL_END`

#echo $sql | read jobname jobstatus

echo $sql

echo $v_JobName

echo $v_JobStatus

#sqlplus /nolog

if [ "$?" != 0 ]; then

# handle error

echo "Could not find SQLPLUS"

and it gives following output.

[c_swalavalkar@s-ipcdev-01 ~]$ ./sql.sh

wf_UCM_CON_ADDR_CONCHLD COMPLETE wf_UCM_CON_ADDR_CONCHLD COMPLETE

DefaultJob

DefaultStatus

[c_swalavalkar@s-ipcdev-01 ~]$

its is printing the values of those columns twice.. and its not setting the values into the variables ;

Can some one help me how to write/modify above script so that I can store the values of those columns into variables?

I want to write an if loop based on the variable values and call ODI scenario through the shell script..

for eg.

if [ $v_JobName == 'XYZ' AND $v_JobStatus =='Comlete' ]; then

execute the scenario 'ScenarioNme'

fi..

Thanks and Regards

Santy

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 12 2013
Added on Jul 15 2013
2 comments
3,262 views