how to call oracle stored procedure from unix shell


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to call oracle stored procedure from unix shell
# 1  
Old 02-25-2010
how to call oracle stored procedure from unix shell

Hi

i want to call a oracle stored procedure from unix (using bash shell).

consider this is my oracle stored procedure with parameter

create procedure testproc(name IN varchar, age IN Number, id OUT Number )

AS

begin
id=1;
dbms_output.put.line('successfull validation')

end;



i want to call the stored procedure and want to store the return value from stored procedure into a variable in unix(bash shell).

also i want to display the dbms_output.putline content into unix(bash shell)


Thanks
This User Gave Thanks to barani75 For This Post:
# 2  
Old 02-25-2010
Is this related to your previous post? :

https://www.unix.com/shell-programmin...procedure.html
# 3  
Old 02-25-2010
call store procedure

Hi

its differrent from my previous post.

Thanks.

---------- Post updated at 10:44 PM ---------- Previous update was at 09:25 PM ----------

Hi

can provide the script.

thanks.
# 4  
Old 02-26-2010
Try this,


Code:
#!/bin/sh
sqlplus -s username/password<<END
execute procedure_name( parameters,....)
Commit;
exit;
END


eg:

sqlplus -s scott@dbase/tiger<<END
execute test_proc(nila,20,101);
commit;
exit;
END


after this save and exit from editor
and run in from the uix prompt... sh sciptname

it will work..
# 5  
Old 02-26-2010
call store procedure

Hi nila

exec procedure();
is not working.
but i tried call procedure(); it was working.

but my concern is

the stored procedure has a OUT parameter and i want to use the out parameter value in unix script.

Thanks
# 6  
Old 02-26-2010
Here is one idea:

- inside your pl/sql code, use UTL_FILE package to write the value of the out parameter into a unix file
- from your shell script, read the value from the file

If you want to avoid writing the value to a file, you can write the output to stdout and use the back-quote operator in the shell script to assign the stdout value to some shell variable.

Thanks.
# 7  
Old 02-26-2010
UTL_FILE won't work if his database is running on a different machine than his shell script.

Try this.

Code:
$ cat use_oracle_proc.ksh
#!/bin/ksh

run_sql()
{
  $ORACLE_HOME/bin/sqlplus -S $scott@dbase/tiger <<EOF
  SET PAGESIZE 0;
  SET FEEDBACK OFF;
  SET SERVEROUT ON;
  VAR major NUMBER;
  VAR minor NUMBER;
  EXEC DBMS_PROFILER.GET_VERSION (:major, :minor);
  PRINT major;
  PRINT minor;
EXIT;
EOF
}

set -A ARRAY $(run_sql)
ARRAYCOUNT=${#ARRAY[*]}
ARRAYIDX=0

while (( $ARRAYIDX < $ARRAYCOUNT ))
do
 echo  "ARRAY[$ARRAYIDX]=(${ARRAY[ARRAYIDX]})"
 ARRAYIDX=$(($ARRAYIDX+1))
done

exit 0

$ ./use_oracle_proc.ksh
ARRAY[0]=(2)
ARRAY[1]=(0)

This User Gave Thanks to SFNYC For This Post:
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 run Oracle stored procedure from UNIX env

Hi Everyone, I want to create a script where i need to run the oracle stored procedure from unix script and get the output(sequence number ) into a variable which i will pass in my datastage job. Below is my stored procedure:- DECLARE P_TRANSTYPE VARCHAR2(20); ... (4 Replies)
Discussion started by: prasson_ibm
4 Replies

2. Shell Programming and Scripting

How to call stored procedure with CLOB out parameter from shell script?

I have written a stored procedure in oracle database, which is having a CLOB OUT parameter. How can i call this stored procedure from shell script and get the CLOB object in shell script variable? (0 Replies)
Discussion started by: vel4ever
0 Replies

3. Shell Programming and Scripting

How to call a stored procedure from shell program?

How to call a stored procedure from shell program (1 Reply)
Discussion started by: noorm
1 Replies

4. Shell Programming and Scripting

Call and redirect output of Oracle stored procedure from unix script

Hi, Can you assist me in how to redirect the output of oracle stored procedure from unix script? Something similar to what i did for sybase isql -U$MYDBLOG -D$MYDBNAME -S$MYDBSVR -P$MYDBPWD -o$MYFILE<< %% proc_my_test 8 go %% Thanks in advance - jak (0 Replies)
Discussion started by: jakSun8
0 Replies

5. Shell Programming and Scripting

how to pass the values to unix shell from the oracle stored procedure.

Hi i am calling a stored procedure from unix shell like this call test_proc('0002','20100218'); the stored procedure was giving output like this dbms_output.put_line(' processed earlier'); i want to see the output in the unix shell where i called. Thanks barani (6 Replies)
Discussion started by: barani75
6 Replies

6. Shell Programming and Scripting

Need to call stored procedure from unix script

Hi Guys, I have a stored procedure which has 5 out parameters. I need to call the stored procedure from the script. When i use the following in my script, db2 "CALL FCFM.PART_MASTER_TMP($Return_code,$Message,$Message1,$SQL,$Load_count)" >> $LOG_FILE I am getting an error.. Please... (1 Reply)
Discussion started by: mac4rfree
1 Replies

7. Shell Programming and Scripting

Invoking Oracle stored procedure in unix shell script

Here's a shell script snippet..... cd $ORACLE_HOME/bin Retval=`sqlplus -s <<eof $TPDB_USER/april@$TPD_DBCONN whenever SQLERROR exit 2 rollback whenever OSERROR exit 3 rollback set serveroutput on set pages 999 var status_desc char(200) var status_code... (1 Reply)
Discussion started by: hidnana
1 Replies

8. Shell Programming and Scripting

Calling an Oracle Stored Procedure from Unix shell script

hai, can anybody say how to call or to execute an oracle stored procedure in oracle from unix... thanks in advance.... for ur reply.... by, leo (2 Replies)
Discussion started by: Leojhose
2 Replies

9. Shell Programming and Scripting

Shell arrays in oracle stored procedure

Is it possible to pass unix shell arrays in Oracle stored procedure? Is yes, how? Thanks (6 Replies)
Discussion started by: superprogrammer
6 Replies

10. Shell Programming and Scripting

Execute an Oracle stored procedure from a shell scrip

Here is a snippet of my code: if then echo "\n Deleting all reports older than 24 hours. \n" >> $logfile ls -l $FileName >> $logfile ... (1 Reply)
Discussion started by: mh53j_fe
1 Replies
Login or Register to Ask a Question