Solved

How to execute an Oracle SP from Shell Script

Posted on 2004-10-06
4
483 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 100 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Unix / Linux grid computing 5 169
bigDiff challenge 17 137
My project did see openJDK that I installed. What could be the problem 7 162
changeXy challenge 13 94
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

696 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