Solved

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

Posted on 2004-08-02
5
11,437 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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Fill Null values 5 37
oracle date format checking 7 34
how to tune the query 17 63
Need help installing oracle client,it is not installing. 3 27
Truncate is a DDL Command where as Delete is a DML Command. Both will delete data from table, but what is the difference between these below statements truncate table <table_name> ?? delete from <table_name> ?? The first command cannot be …
Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
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.

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