Shell script to catch PL/SQL return values


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script to catch PL/SQL return values
# 22  
Old 03-24-2010
Nope, it ain't good enough.

Run the 3 commands in point # 2 of my earlier post on your Unix/Linux shell prompt and copy/paste the console session over here within "code" tags.

tyler_durden
# 23  
Old 03-24-2010
Code:
 
cognos@sec-dev-sun04 : cat -n ./monie_test.sh
     1   !/bin/sh
     2  ###############################################################################
     3  #set -vxf
     4  
     5  COGNOS_HOME=/opt/cognos/cer/bin
     6  PATH=/usr/bin:/usr/sbin:/usr/local/bin:/opt/oracle/product/9.2.0/bin
     7  MODEL_HOME=/opt/cognos/mis_bi/models/Shipment
     8  TNS_ADMIN=/opt/oracle/product/9.2.0/network/admin
     9  CLASS_PATH=/opt/cognos/cognos8/webapps/p2pd/WEB-INF/lib
    10  PREF=/opt/cognos/preferences
    11  LD_LIBRARY_PATH=/opt/oracle/product/9.2.0/lib:/opt/cognos/cer/bin
    12  
    13  CUBE_SRC=/opt/cognos/mis_bi/cubes/Shipment/shipment_build
    14  CUBE_TRGT=/opt/cognos/mis_bi/cubes/Shipment
    15  HOSTNAME=`hostname`
    16  
    17  export COGNOS_HOME MODEL_HOME PREF PATH TNS_ADMIN CLASS_PATH LD_LIBRARY_PATH ORACLE_HOME CUBE_SRC HOSTNAME CUBE_TRGT
    18  
    19  TODAY=$(date)
    20  
    21  ORACLE_HOME=/opt/oracle/product/9.2.0
    22  ORACLE_SID=$1
    23  echo "Date is Fridayyyyy: $TODAY"
    24  x=$($ORACLE_HOME/bin/sqlplus -s report/report@$ORACLE_SID <<EOF
    25  set heading off pages 0 feedback off
    26  var n varchar2(100)
    27  exec select mod_cd into:n from report.cube where cube_cd = 'LNR_ALL';
    28  print :n
    29  exit;
    30  EOF)
    31  echo "Count = $x"
    32  
    33  
    34


Last edited by monie2717; 03-24-2010 at 02:33 PM..
# 24  
Old 03-24-2010
Nope, still not good enough.

You still haven't run the 2nd command ("od -bc...") of the 2nd point of my earlier post.

Also, your shebang on line # 1 is incorrect. Fix that as per my scripts posted earlier.

tyler_durden
# 25  
Old 03-24-2010
sorry about that .. done as attachments
# 26  
Old 03-24-2010
Ok, so your "od" or "octal dump" output looks good -

Code:
...
0001700 145 040 143 165 142 145 137 143 144 040 075 040 047 114 116 122
           e       c   u   b   e   _   c   d       =       '   L   N   R
0001720 137 101 114 114 047 073 012 160 162 151 156 164 040 072 156 012
           _   A   L   L   '   ;  \n   p   r   i   n   t       :   n  \n
...

The "047" corresponds to the character on left of "L" in "LNR..." and to the one on right of "L" in "_ALL".

Octal 047 = Decimal 39 which is the ASCII number of the single quote character. So this rules out any surprises over there.

Nevertheless, this beats me.

My best bet is that because you haven't set your shebang properly, your shell is doing something dodgy.

Do the following:

(1) Find out what shell you are using.

Code:
echo $SHELL

(2) Find out if you have Bash shell.

Code:
type bash

(3) If you have Bash shell, then use that path in the script's shebang.

(4) Otherwise, use the Bourne shell (sh) and -

(4a) add the correct path in the script's shebang

Code:
type sh

and
(4b) change the $() operator to the backtick (``) operator. That is, change this -

Code:
x=$($ORACLE_HOME/bin/sqlplus ...
...
      EOF)

to this -

Code:
x=`$ORACLE_HOME/bin/sqlplus ...
...
      EOF`

HTH,
tyler_durden
# 27  
Old 03-30-2010
Last suggestion worked Smilie thanks
# 28  
Old 03-30-2010
Glad to know it worked!

Cheers,
tyler_durden
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to catch sql error in script?

Hi Gurus, I have a script which send sql query to oracle db and return value to my script. dummy code like below: sqlplus -s user/${PASSWD}@${ORACLE_SID} @${DIR}/query.sql > outputfile using above code, when query has error, it send error to same out put file and exit code is 0, is... (6 Replies)
Discussion started by: ken6503
6 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. Shell Programming and Scripting

Query the table and return values to shell script and search result values from another files.

Hi, I need a shell script, which would search the result values from another files. 1)execute " select column1 from table_name" query on the table. 2)Based on the result, need to be grep from .wft files. could please explain about this.Below is the way i am using. #!/bin/sh... (4 Replies)
Discussion started by: Rami Reddy
4 Replies

4. 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

5. Shell Programming and Scripting

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... (1 Reply)
Discussion started by: MxC
1 Replies

6. Shell Programming and Scripting

calling pl/sql procedure from shell and return values

How could I call an Oracle PL/SQL procedure from any shell (bash) and catch returning value from that procedure (out param) or get a returning value if it's a function. also, I got into trouble when I tried to send a number as a param #!/bin/bash -e username=$1 pwd=$2 baza=$3... (0 Replies)
Discussion started by: bongo
0 Replies

7. Shell Programming and Scripting

how to store the return values of stored procedure in unix shell script.

hi i am calling a oracle stored procedure(in the database) from unix shell scripting (a.sh). the called stored procedure returns some values through OUT variables i want to assign the return values of stored procedure in to unix shell script variable. can you provide me the code. ... (1 Reply)
Discussion started by: barani75
1 Replies

8. 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

9. 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

10. Shell Programming and Scripting

passing values from sql to shell script

Hi guyz, Posting a thread after a long time. I want to pass two variables to unix shell script from sql script. Note: I am calling sql script from unix script. sql script has 2 variables one is the return code for status of program run and second one email flag. I don't know how to capture... (3 Replies)
Discussion started by: sachin.gangadha
3 Replies
Login or Register to Ask a Question