Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to execute an Oracle SP from Shell Script

Posted on 2004-10-06
4
Medium Priority
?
521 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 12

Expert Comment

by:catchmeifuwant
ID: 12236049
exec sp_name(param1,param2,param3...ect)

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

Author Comment

by:dhaneshgesota
ID: 12236078
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
ID: 12236093
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 300 total points
ID: 12236128
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

636 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