Solved

SQL*Plus Syntax for calling Stored Procedure (some have IN Parameters , some don't)

Posted on 2004-08-02
5
11,434 Views
Last Modified: 2010-10-05
Thru the SQL*Plus client's console  I am able to execute  the Open SQL below:
   select * from user_objects where object_type = "PACKAGE";

I can also execute the JLOs_Proc1 and JLOs_Proc1 Stored Procs below (from a VC++ client application)

?
How do I call the JLOs_Proc1 and JLOs_Proc1 Stored Procs from the SQL*Plus  prompt
?

create or replace package JLOs_pkg is
type genericCursor is ref cursor;
end JLOs_pkg;
/
create or replace procedure JLOs_Proc1 ( sp_cursor OUT JLOs_pkg.genericCursor )
is
begin
open sp_cursor  for select * from user_objects;
end;
/
create or replace procedure JLOs_Proc2 ( prm_1 IN varchar2, sp_cursor OUT JLOs_pkg.genericCursor )
is
begin
open sp_cursor  for select * from user_objects where object_type = prm_1 order by created;
end;
/
create or replace procedure JLOs_Proc3 ( prm_1 IN varchar2, prm_2 IN number, sp_cursor OUT JLOs_pkg.genericCursor )
is
begin
open sp_cursor  for select * from user_objects where object_type = prm_1 and object_id = prm_2;
end;
0
Comment
Question by:jjlloorrttiizz
5 Comments
 
LVL 23

Expert Comment

by:seazodiac
ID: 11697321
in sqlplus window, you call stored procedure in one of two ways;


BEGIN
<procedure_name with params>;
END;
/

or

execute <procedure_name with params>;

0
 
LVL 35

Expert Comment

by:Mark Geerlings
ID: 11698089
Yes, seazodiak gave you the syntax for executing PL\SQL procedures from SQL*Plus.  To execute functions, the syntax is slightly different (you just list them in a select statement like you would list a column name), but I am not sure that SQL*Plus supports executing stored procedures that return ref cursors.  In SQL*Plus, I would normally just execute the select statement directly, and not try to add the PL\SQL layer in between.
0
 
LVL 7

Accepted Solution

by:
BobMc earned 60 total points
ID: 11698573
I run most of my reports this way, so I get the flexibilty of PL/SQL to generate the data sets, and the (often under-rated) built in report formatting capabilities of SqlPlus


From SqlPlus:

VARIABLE bob REFCURSOR;

EXECUTE JLOs_Proc1 (:bob);

PRINT :bob;


HTH
Bob
0
 
LVL 22

Assisted Solution

by:earth man2
earth man2 earned 40 total points
ID: 11698631
SQL> create or replace procedure JLOs_Proc3 ( prm_1 IN varchar2, prm_2 IN number, sp_cursor OUT sys_refcursor )
is
begin
open sp_cursor  for select * from user_objects where object_type = prm_1 and object_id = prm_2;
end;
/
SQL> variable cur refcursor;
SQL> execute JLOs_Proc3('JAVA SOURCE',38877, :cur );
SQL> print cur;

dmf_fnd_ww_dirList
                                    38877                JAVA SOURCE
16-JUL-04 17-JUL-04 2004-07-17:00:25:54 VALID   N N N
0
 

Author Comment

by:jjlloorrttiizz
ID: 11698897
Thanks Bob, for the sample code for the Proc that takes no In parms (It worked the first time)

Thanks earthman2, for the sample code for the Proc that takes In parms (It worked the first time, after I plugged in values for my environment)

- This is my first - I hope I followed correct EE Protocol, regarding splitting points and accepting the first correct comment/answer...
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Article by: Swadhin
From the Oracle SQL Reference (http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/queries006.htm) we are told that a join is a query that combines rows from two or more tables, views, or materialized views. This article provides a glimps…
This article started out as an Experts-Exchange question, which then grew into a quick tip to go along with an IOUG presentation for the Collaborate confernce and then later grew again into a full blown article with expanded functionality and legacy…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.

777 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