calling pl/sql procedure from shell and return values


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting calling pl/sql procedure from shell and return values
# 1  
Old 04-16-2010
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
Code:
#!/bin/bash -e
 
username=$1
pwd=$2
baza=$3
procedure=$4
var1=$5
var2=0
sqlplus -s -l $username/$pwd@$baza<<END
execute $procedure('$var1',$var2);
commit;
exit;
END
echo $var2


pl/sql procedure looks like
Code:
CREATE OR REPLACE procedure ttt(var1 in varchar2, var2 in out number) return number as

begin
    insert into korisnik_temp(kor_inicia, kor_opisno) values(1, var1);
    var2:=0;
exception
    when others then
    var2:=-1;
end;



---------- Post updated at 02:14 PM ---------- Previous update was at 01:37 PM ----------

I managed to make it.

the script goes like:
Code:
#!/bin/bash -e

username=$1
pwd=$2
baza=$3
procedure=$4
var1=$5

vvarr=$(sqlplus -s -l $username/$pwd@$baza<<END
set heading off;
set feedback off;
var var2 Number;
execute $procedure('$var1',:var2);
print var2;
commit;
exit;
END)
echo $vvarr
~

Smilie

Last edited by pludi; 04-16-2010 at 08:49 AM.. Reason: code tags, please...
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 Pass the Output Values from the PL/SQL Procedure to Shell Script?

hi, Could anyone tell me how to pass the output values of the PL/SQL procedure to Shell script and how to store that values in a shell script variable... Thanks in advance... (5 Replies)
Discussion started by: funonnet
5 Replies

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

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

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

5. Shell Programming and Scripting

Calling procedure through Unix Shell

how to 1) invoke batch profile to run sqlplus on XXXXX server. 2) execute truncate table xtra.xtra_card_email_request using procedure dbadmin.truncate_table . 3) Check the count before and after the job run. (1 Reply)
Discussion started by: jakred
1 Replies

6. Programming

Calling procedure through Unix Shell

Hi can anyone help me in how to 1) invoke batch profile to run sqlplus on XXXXX server. 2) execute truncate table xtra.xtra_card_email_request using procedure dbadmin.truncate_table . 3) Check the count before and after the job run. (1 Reply)
Discussion started by: jakred
1 Replies

7. Shell Programming and Scripting

calling a PL/SQL stored procedure from KSH

Hi I have a stored procedure which should be called from KSH. Could ayone please help me with this. Thanks (1 Reply)
Discussion started by: BlAhEr
1 Replies

8. Shell Programming and Scripting

Calling stored procedure from shell script

HI, I have a similar problem to thread 18264, only I couldn't get it to work. https://www.unix.com/showthread.php?t=18264 I have a stored procedure which is called by a shell script program. When I run the stored procedure alone or through the shell script, it works fine with output text... (3 Replies)
Discussion started by: dorisw
3 Replies

9. Shell Programming and Scripting

calling stored procedure from shell script.

Hi All, This is a very starnge problem I am having. I have a shell script that calls a stored procedure. Here's my code in shell script: sqlplus "userid/pwd" @file.sql and file.sql has the following statement: exec my_storedProc; Now, when I execute my shell script, nothing... (2 Replies)
Discussion started by: priyamurthy2005
2 Replies

10. 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
Login or Register to Ask a Question