Assigning return value of an embedded SQL in a shell script variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Assigning return value of an embedded SQL in a shell script variable
# 1  
Old 08-24-2010
Assigning return value of an embedded SQL in a shell script variable

I've a script of the following form calling a simple sql that counts the no of rows as based on some conditions. I want the count returned by the sql to get assigned to the variable sql_ret_val1. However I'm finding that this var is always getting assigned a value of 0. I have verified by executing the sql statement via sqlplus that I am indeed having 1 being returned as a count with my given conditions.

Code:
#!/bin/ksh
export SUCCESS=0
export ERROR=1
...
typeset -i sql_ret_val1=`sqlplus -s ${ORA_CONN_STR} <<EOF > /dev/null
SET HEADING OFF

SELECT COUNT (1) FROM <table> WHERE <condition1> AND <condition2>;

EOF`

if [ ${sql_ret_val1} -ne 0 ]
then
   echo &quot;SQL returned count is: ${sql_ret_val1}&quot;
   mailx -s &quot;Values found&quot; ${MAIL_RECIP} < ${LOG_FILE}
   return ${ERROR}
else
   echo &quot;SQL returned count is: ${sql_ret_val1}&quot;
   mailx -s &quot;No values found&quot; ${MAIL_RECIP} < ${LOG_FILE}
   return ${SUCCESS}
fi
...

Any suggestions?

---------- Post updated at 15:06 ---------- Previous update was at 14:56 ----------

Guys, you can ignore the above post. I myself realized that the problem was due to the following:
Code:
typeset -i sql_ret_val1=`sqlplus -s ${ORA_CONN_STR} <<EOF > /dev/null

Which when corrected as following, started to work:
Code:
typeset -i sql_ret_val1=`sqlplus -s ${ORA_CONN_STR} <<EOF

# 2  
Old 08-24-2010
Hi.

You have thrown the output away (to /dev/null), and one or two more sets wouldn'g go amiss:

Change:
Code:
typeset -i sql_ret_val1=`sqlplus -s ${ORA_CONN_STR} <<EOF > /dev/null
SET HEADING OFF

To:
Code:
typeset -i sql_ret_val1=`sqlplus -s ${ORA_CONN_STR} <<EOF
SET HEADING OFF FEEDBACK OFF PAGESIZE 0



---------- Post updated at 11:39 AM ---------- Previous update was at 11:37 AM ----------

Ah. Didn't see your update Smilie
This User Gave Thanks to Scott For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Assigning an expression to a variable in shell script

i am trying to assign the following expression to a variable in Unix shell script and want to use that variable in some other expression. But unable to get the required thing done. Please help with this.... This is the expression which i want to provide as input the variable date '+%y:%m:%d' |... (3 Replies)
Discussion started by: ssk250
3 Replies

2. Shell Programming and Scripting

Return value to shell script, depending on status of pl/sql udpate

Hi All, I need to return value to the main shell script, depending on whether the UPDATE command in the embedded pl/sql is successfu or not. #!bin/ksh updateStatus=`sqlplus --conn details-- << EOF DECLARE var_rows NUMBER; BEGIN update table_name set column_name =... (7 Replies)
Discussion started by: rituparna_gupta
7 Replies

3. UNIX for Advanced & Expert Users

Call parallel sql scripts from shell and return status when both sql are done

Hi Experts: I have a shell script that's kicked off by cron. Inside this shell script, I need to kick off two or more oracle sql scripts to process different groups of tables. And when both sql scripts are done, I will continue in the shell script to do other things like checking processing... (3 Replies)
Discussion started by: huasheng8
3 Replies

4. Shell Programming and Scripting

Shell script to catch PL/SQL return values

I tried searching the forum for similar posts but its closed now. Would appreciate any help on this. I am trying to capture return value from a select query into a variable. DB is Oracle I am able to spool it to a file but I donot intend to use it. Here is my script that does not work ;) I... (27 Replies)
Discussion started by: monie2717
27 Replies

5. Shell Programming and Scripting

Assigning value of SQL output to a variable in shell scripting

I am trying to assgn the output of the select statement to a variable, like this "VARIABLE_NAME=$ db2 "select COLUMN_NAME_1 from TABLE_NAME where COLUMN_NAME_2='VALUE_TO_CHECK'"; " but the value that is getting into VARIABLE_NAME is "COLUMN_NAME_1 ----------------- VALUE 1... (3 Replies)
Discussion started by: sgmini
3 Replies

6. Shell Programming and Scripting

Need to return fail or pass from shell script on the basis of pl/sql code execution

Hi guys, I am quite new in shell scripting. I am tring to promote some oracle jobs into control-M. In control-M, I am calling a script which establishes a connection with database and execute some procedures. Now I want if that PL/sql Block got failed script should return failure to... (2 Replies)
Discussion started by: alok1301
2 Replies

7. Shell Programming and Scripting

Shell script to catch PL/SQL return values

Hello, I need some help from the experts on PL/SQL and Shell scripting. I need a shell script that runs a PL/SQL procedure and gets the values returned from the PL/SQL procedure into the shell variables. The PL/SQL procedure returns multiple values. I was able to assign a single return value... (1 Reply)
Discussion started by: Veera_Raghav
1 Replies

8. Shell Programming and Scripting

Bourne shell script with embedded Sybase SQL

Hi, I need a simple (as possible) Bourne shell script that takes an input file of adminID's and spits out a list of adminID's and related tradeID's. Both adminID and tradeID are columns in a Sybase database table called "trades", in which they have a one-to-one relationship. adminID is a... (3 Replies)
Discussion started by: chatieremerrill
3 Replies

9. Shell Programming and Scripting

return variable from PL/SQL procedure to shell

Hi i'm calling a pl/sql procedure which is returning one variable. i'm trying to assing this value to variable in shell script the code i wrote is ** in shell script** var= 'sqlplus user/pass @ret.sql' echo $var ** and variable dum_var number exec rt_test(:DUM_VAR); exit; in... (4 Replies)
Discussion started by: ap_gore79
4 Replies

10. Shell Programming and Scripting

Embedded SQL in AWK script

Hi All, Can I use AWK script to read data from Oracle table (some embedded SQL perhaps) The reason for this that I have a data file and I need to do some basic validations of the data in the file with some statistical figures related to the data file that I have stored in a Oracle table. Thanks... (2 Replies)
Discussion started by: 2nilotpal
2 Replies
Login or Register to Ask a Question