?
Solved

How to execute an Oracle SP from Shell Script

Posted on 2004-10-06
4
Medium Priority
?
504 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses

770 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