Solved

How to execute an Oracle SP from Shell Script

Posted on 2004-10-06
4
432 Views
Last Modified: 2013-12-26
Hi

I am able to execute a normal Oracle SP from the Shell script.
But how do i execute a Oracle SP with parameters from a shell script??

I use the following code to execute a normal Oracle SP from shell script:

sqlplus -s ${ORAID} @<<EOF  >${SQL_RET}
        set pause off;
        set pagesize 0;
        set trimspool on;
        set echo off;
        set feedback off;
        set linesize 1000;
        set verify off;
        set define on;
        set serveroutput on size 1000000;

        exec SP_NAME;
exit;
EOF

STATUS=$?

TIA
Dhanesh
0
Comment
Question by:dhaneshgesota
  • 3
4 Comments
 
LVL 12

Expert Comment

by:catchmeifuwant
Comment Utility
exec sp_name(param1,param2,param3...ect)

If it's a varchar2 then include it in quotes 'param1'
0
 

Author Comment

by:dhaneshgesota
Comment Utility
Does this mean that I can pass the shell script variable to the SP and I dont need to declare an Oracle variable?
0
 
LVL 12

Expert Comment

by:catchmeifuwant
Comment Utility
No if you have created a procedure :

sp_name(p_1 in varchar2,p_2 in number)

Then from your Shell Script, just pass it as:

sqlplus -s ${ORAID} @<<EOF  >${SQL_RET}
        set pause off;
        set pagesize 0;
        set trimspool on;
        set echo off;
        set feedback off;
        set linesize 1000;
        set verify off;
        set define on;
        set serveroutput on size 1000000;

        exec SP_NAME('MYVARP1',100);
exit;
EOF

STATUS=$?
0
 
LVL 12

Accepted Solution

by:
catchmeifuwant earned 100 total points
Comment Utility
Or if you want to pass parameters at runtime, then use another script to execute the sp.

sqlplus user/pass@sid @MYFILE.sql param1 param2

----------------------------------------
Contents of MYFILE.sql
----------------------------------------
set pause off;
        set pagesize 0;
        set trimspool on;
        set echo off;
        set feedback off;
        set linesize 1000;
        set verify off;
        set define on;
        set serveroutput on size 1000000;

exec sp_name('&1',&2);
exit;
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now