passing oracle parameters back to Shell


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting passing oracle parameters back to Shell
# 1  
Old 01-15-2007
passing oracle parameters back to Shell

Hi All,

Does anyone have any solutions for passing back multiple variables back to the SHELL from a call to an ORACLE procedure:

eg
#username='scott'
#password='tiger'
#database='orcl'
username='ITGCD03D03'
password='tC5epIew'
database='ITGCD03D'


sqlplus -s $username/$password@$database<<EOF

set serveroutput on size 1000000
set verify off

VARIABLE vi_err NUMBER
VARIABLE val_err NUMBER;

begin

package.procedure(p_err_out => :vi_err
,p_validation_err_out => :val_err);

dbms_output.put_line('val_err='||:val_err);

end;
/

EXIT:vi_err
EOF

print out values of Vi_err and val_err here????

any feedback would e greatly appreciated!
Kind Regards
Satnam
# 2  
Old 01-15-2007
I don't get it. Are you talking about reading the output of the oracle procedure into shell variables?

Try something like this:
Code:
a=$(sqlplus -s $username/$password@$database<<EOF 

set serveroutput on size 1000000
set verify off

VARIABLE vi_err NUMBER
VARIABLE val_err NUMBER;

begin 

package.procedure(p_err_out => :vi_err
,p_validation_err_out => :val_err);

dbms_output.put_line('val_err='||:val_err); 

end; 
/ 

EXIT:vi_err
EOF
)

Whatever is output by the stuff between the parens will be stored in $a. You can then work on $a to get the values that you need.
# 3  
Old 01-16-2007
passing oracle parameters from the shell

HI MATE

yes what i was getting at was tryin to pass 2 out parameters so that thay can be individually accessed in back in the shell script.

o in the the example I gave, the oracle packaged procedure is executed returning somthing in its OUT parameters :vi_err and :val_err.

The value of :vi_err can be accessed as it is returned in the EXIT command
but Im not sure how to access the value of :val_err.

I could have used a function as suggested but that would only return the 1 variable not both as i would like.. does that make sense?

Kind Regards

Satnam
# 4  
Old 01-16-2007
No need to use exit or any such thing. If you can just get the procedure to print these two values, that should be enough for the shell. The two values will be stored in the variable ($a in my example). Then you can use parameter expansion in bash/ksh to get the two values seperately.
# 5  
Old 01-16-2007
Quote:
Originally Posted by satnamx

Does anyone have any solutions for passing back multiple variables back to the SHELL from a call to an ORACLE procedure:
$ a=($(printf "%s;\n" "set pages 0 serverout on feed off" \
> "exec dbms_output.put_line('Line1')" \
> "exec dbms_output.put_line('Line2')" \
> | sqlplus -s / as sysdba))
$ echo ${a[0]}
Line1
$ echo ${a[1]}
Line2

or:

$ printf "%s;\n" "set pages 0 serverout on feed off" \
> "exec dbms_output.put_line('Line 1')" \
> "exec dbms_output.put_line('Line 2')" \
> | sqlplus -s / as sysdba \
> | { read var1;
> read var2;
> echo "var1 is $var1 , var2 is $var2"
> }
var1 is Line 1 , var2 is Line 2


Regards
Dimitre
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Passing control back to the shell script

Hi All, I have a shell script(test_abc.sh) with the following shell commands, which are invoking the same shell script with different parameters. test_abc.sh . ./test.sh abc >> test.log . ./test.sh xyz >> test.log . ./test.sh pys >> test.log . ./test.sh abc >> test.log . . ... (4 Replies)
Discussion started by: dev.devil.1983
4 Replies

2. Shell Programming and Scripting

Shell Script passing parameters to sqlplus code

Hello All, I am interested in finding out a way to pass parameters that are entered at the prompt from HP unix and passed to SQLPlus code with a Shell Script. Is this possible? Thanks (4 Replies)
Discussion started by: compprog11
4 Replies

3. Shell Programming and Scripting

Passing Variable Parameters (C shell)

I am trying to execute a copy command via shell script. However, on occassion, 2 or more files need to copied. How do I code for the multiple arguments? Does it matter how the files are delimited? Example: I have a script to copy files from 1 dir to another called duplicate.csh In most... (1 Reply)
Discussion started by: CKT_newbie88
1 Replies

4. Shell Programming and Scripting

specified path name is too long passing parameters to awk via shell script

Hello, I have this shell script that runs awk code by passing in parameters however now it doesn't work anymore with the parameters and I don't know why. It removes duplicates from an input file based on a part of the last field and a key column. It removes the record with the older datetime... (0 Replies)
Discussion started by: script_op2a
0 Replies

5. Shell Programming and Scripting

Passing unix variable to oracle parameters

Please help me how to pass some unix vairable to oracle. I have used below , but not displaying passed (inval) value. calling() { sqlplus -s $1/$2@$3 <<EOF begin exec call_sql($4); end; exit EOF } calling user pwd inst value1... (17 Replies)
Discussion started by: Jairaj
17 Replies

6. Shell Programming and Scripting

Shell Script Passing Parameters For Directory Listing

i have this basic piece of code that i am trying to debug to accept input parameter to be able to display a directory listing of files. cd /u02/app/eatv/dev/out CURDIR=`pwd` echo directory listing of $CURDIR echo if ; then ls -latr else ls -latr $1 fi basically if the script... (9 Replies)
Discussion started by: wtolentino
9 Replies

7. Shell Programming and Scripting

Passing parameters to Shell script for GREP command

I am using grep to capture date from a file . Since i need to use the shell script for different dates ,is it possible to pass the date parameter to the shell script the Script is as below grep -E "08 Aug 2008|2008-08-08"* somefile.txt>test.txt The above script file greps the... (1 Reply)
Discussion started by: sud.tech
1 Replies

8. Shell Programming and Scripting

Passing parameters form unix to Oracle procedure

Hi, I have screen which was desined in PL/SQL Catridges in apps. In that screen some enterable fields these values r the passing parameters to create value sets, functions, menus etc in apps by using front end screens. Now in that screen i have a button. when i click that button it have to... (0 Replies)
Discussion started by: rajasekharamy
0 Replies

9. Programming

Passing Parameters and getting values back from a c program to Shell script

I am having a shell script which has to be called from a C program. I have to pass two parameters to this script. HOw can I do that? eg: int main() { char st1; char str2; // call a shell script call_sh(str1,str2) where call_sh is the name of the shell script. then i need to get the return... (5 Replies)
Discussion started by: Rajeshsu
5 Replies

10. Shell Programming and Scripting

passing parameters from a shell script to sqlplus

Hi , I want to pass parameters from a shell script to a sql script and use the parameter in the sql query ..and then I want to spool a particular select query on to my unix box... for 4 different locations by writing only one sql script Right now no file is generated on the unix box...it is a... (2 Replies)
Discussion started by: phani
2 Replies
Login or Register to Ask a Question