Solved

How to execute an Oracle SP from Shell Script

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Expand data scrubbing tool 13 32
scoreUp challenge 14 62
noX challenge 17 112
Work with App store 7 51
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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 Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

785 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