How to pass a oracle variable back to the shell script


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to pass a oracle variable back to the shell script
# 1  
Old 07-08-2005
How to pass a oracle variable back to the shell script

Hi,

I am calling an oracle function that returns a number (either 0 or 2), how do I pass that pass to the wrapping shell script as I would like to do other things based on the value returned by the oracle function.

Your help will be appreciated.

--------------------------
sqlplus / << ENDPROG
declare
return_code integer;
begin
return_code := kf_pkg_load.df_validate_file('SAS','20050612',null,null,null,null,null,null,null,null);
commit;
end;
/
exit;
ENDPROG
---------------------------
# 2  
Old 07-08-2005
Quote:
Originally Posted by Jtrinh
Hi,

I am calling an oracle function that returns a number (either 0 or 2), how do I pass that pass to the wrapping shell script as I would like to do other things based on the value returned by the oracle function.

Your help will be appreciated.

--------------------------
sqlplus / << ENDPROG
declare
return_code integer;
begin
return_code := kf_pkg_load.df_validate_file('SAS','20050612',null,null,null,null,null,null,null,null);
commit;
end;
/
exit;
ENDPROG
---------------------------
Assign a variable to the sqlplus call. I belive you do not need to assign the
return code.

Code:
result=sqlplus / << ENDPROG
declare
return_code integer;
begin
return_code := kf_pkg_load.df_validate_file('SAS','20050612',null,null,null,null,null,null,null,null);
commit;                         
end;
/

This is how I would do it:

Code:
part_info=`sqlplus -s ${DB_USER:}/${DB_PASSWORD:}@${ORACLE_SID} <<_EOF_

      set feedback off
      set linesize 100
      whenever sqlerror exit failure;
      set lines 150
      set pages 0
      set head off
      set serveroutput on size 10000
  
      kf_pkg_load.df_validate_file 
      'SAS','20050612',null,null,null,null,null,null,null,null);
                    
      exit;
      _EOF_`

Then I evaluate the variable to get the results or see if an error occured. You should see what the df_validate_file returns or an error if one occured.

Hope this helps Smilie
# 3  
Old 07-10-2005
Thanks VIGSGB for responding, I tried to run this (I had to make some changes to make it run):

----------------------------------
part_info=`sqlplus sars2d/oracle@kfdmlc <<_EOF_
set serveroutput on size 10000
declare
abc integer;
begin
abc:= kf_pkg_load.df_validate_file(
'SAS','20050612',null,null,null,null,null,null,null,null);
dbms_output.put_line('return code is:'||abc) ;
end;
/
exit;
_EOF_`
------------------------------

However, when I do an echo on part_info, it returns this:

------------------------------------
SQL*Plus: Release 9.2.0.1.0 - Production on Mon Jul 11 12:50:24 2005 Copyright (
c) 1982, 2002, Oracle Corporation. All rights reserved. Connected to: Oracle9i E
nterprise Edition Release 9.2.0.1.0 - 64bit Production With the Partitioning opt
ion JServer Release 9.2.0.1.0 - Production SQL> SQL> 2 3 4 5 6 7 8 start date is
: current load instance id is : last load instance id is : 122 return code is:0
PL/SQL procedure successfully completed. SQL> Disconnected from Oracle9i Enterpr
ise Edition Release 9.2.0.1.0 - 64bit Production With the Partitioning option JS
erver Release 9.2.0.1.0 - Production
-----------------------------------

What am I doing wrong?

Thanks in advance.

JTrinh
# 4  
Old 07-11-2005
You need to run sqlplus with the "-S" parameter to keep the sqlplus version text from muddying up your process.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need to pass Oracle SQL output to Linux and back... Help!

Hi all, Hopefully you can help. This is what I'm trying to achieve: Obtain a list of usernames out of an Oracle Database Based on this list, link each username with an Oracle Internet Directory (OID) GUID Using the username and GUID perform a database update for all users Here are the... (7 Replies)
Discussion started by: exm
7 Replies

2. Shell Programming and Scripting

How to pass Oracle sql script as argument to UNIX shell script?

Hi all, $ echo $SHELL /bin/bash Requirement - How to pass oracle sql script as argument to unix shell script? $ ./output.sh users.sql Below are the shell scripts and the oracle sql file in the same folder. Shell Script $ cat output.sh #!/bin/bash .... (7 Replies)
Discussion started by: a1_win
7 Replies

3. Shell Programming and Scripting

Pass a variable string in To_Date Oracle function in shell script

Hello, I am trying to execute an SQL query from shell script. A part of script is something like this: fromDate=`echo $(date +"%F%T") | sed "s/-//g" | sed "s/://g"` $ORACLE_HOME/sqlplus -s /nolog <<EOD1 connect $COSDBUID/$COSDBPWD@$COSDBSID spool... (4 Replies)
Discussion started by: sanketpatel.86
4 Replies

4. Shell Programming and Scripting

Unable to pass shell script variable to awk command in same shell script

I have a shell script (.sh) and I want to pass a parameter value to the awk command but I am getting exception, please assist. diff=$1$2.diff id=$2 new=new_$diff echo "My id is $1" echo "I want to sync for user account $id" ##awk command I am using is as below cat $diff | awk... (2 Replies)
Discussion started by: Ashunayak
2 Replies

5. UNIX for Dummies Questions & Answers

Pass value back to unix variable

i had this unix korn shell code that connects to oracle database and execute the oracle procedure. i need to add a variable that indicates the oracle procedure failed. basically the variable is to check if the oracle procedure failed it will assign 1 and when the variable is equal to 1 it will not... (4 Replies)
Discussion started by: wtolentino
4 Replies

6. Shell Programming and Scripting

pass variable from awk to shell script

Hello Experts, Actually I was searching for a solution here in this forum , but didn't get what exactly I want . Is this possible to do in awk ? I am trying to do some thing like below in ksh script . Upto my knowledge I can pass shell script to awk with "-v " option. But I... (3 Replies)
Discussion started by: user_prady
3 Replies

7. Shell Programming and Scripting

Is it possible to pass variable from awk to shell back

I am passing a varaible to from Shell to awk then I am doing some maniplation for that variable inside awk. I want that maniplated variable value back to shell , Is this possible .Please let me know. (12 Replies)
Discussion started by: unishiva
12 Replies

8. UNIX for Dummies Questions & Answers

How to pass Shell script variable to awk

Hi, I have a shell script with an ambedded awk script. i need to pass a script variable to the awk script. Please help. Thanks in advance Himani (3 Replies)
Discussion started by: HIMANI
3 Replies

9. UNIX for Dummies Questions & Answers

how to pass values from oracle sql plus to unix shell script

how to pass values from oracle sql plus to unix shell script (2 Replies)
Discussion started by: trichyselva
2 Replies

10. UNIX for Dummies Questions & Answers

How to Pass variable to shell Script

Hi , i am beginner to Unix, I have one small script which execute java programme,it has java command input output structure . Right now i have given Input output structure manually that is on same directory, now how can i pass that by commandline #!/bin/sh java Classjava input.txt... (5 Replies)
Discussion started by: sam70
5 Replies
Login or Register to Ask a Question