Solved

help with Oracle stored procedure with input and output parameters

Posted on 2014-09-30
8
673 Views
Last Modified: 2014-10-01
I have an Oracle stored procedure that I’ve ported from DB2. It has one input parameter, and it returns a result-set. In DB2, the procedure-header would look like this:

create procedure MySP(
  IN someInputParm varchar(20) 
)
RESULT SETS 1                                 
...

Open in new window


Calling it would be simply:

Call MySP ('some value')

Open in new window


... and the result-set would be returned to the calling program.

In Oracle, I believe I need to include the result-set in the procedure's parameters:

CREATE OR REPLACE PROCEDURE MySchema.MySP (someInputParm VARCHAR2, 
                                           mycursor OUT SYS_REFCURSOR,
)
IS
...

Open in new window


In Oracle, calling it with EXEC works beautifully:

var rc refCursor;
exec MySchema.MySP ('V14', :rc);
print rc;

THE_PK            CREATEDTIMESTAMP CREATEDBY           
----------------- ---------------- --------------------
                5 04-SEP-08        USER1
                6 24-SEP-08        USER2
                9 09-SEP-10        USER3             

Open in new window


But, calling it with CALL (as I would do in DB2) throws an error:

var rc refCursor;
call MySchema.MySP ('V14', :rc);
print rc;

Error at line 2
ORA-06553: PLS-306: wrong number or types of arguments in call to 'MYSP'

Open in new window


So, what’s the difference between calling a stored procedure with CALL and calling it with EXEC. I’ve Googled this, but I haven’t come up with anything definitive.

Thanks in advance!
DaveSlash
0
Comment
Question by:daveslash
  • 4
  • 3
8 Comments
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 40352772
What tool/product are you using to run that SQL?

What version of Oracle are you using?

Using 11.2.0.2 and sqlplus, it works for me:
SQL> create or replace procedure myproc(p1 varchar2, p2 out sys_refcursor)
  2  is
  3  begin
  4  open p2 for 'select sysdate from dual';
  5  end;
  6  /

Procedure created.

SQL>
SQL> show errors
No errors.
SQL>
SQL> var mycur refcursor
SQL> exec myproc('a',:mycur);

PL/SQL procedure successfully completed.

SQL> print mycur

SYSDATE
---------
30-SEP-14

SQL>
SQL> call myproc('a',:mycur);

Call completed.

SQL> print mycur

SYSDATE
---------
30-SEP-14

SQL>
SQL>

Open in new window

0
 
LVL 18

Author Comment

by:daveslash
ID: 40352793
Thanks for a quick response!

I'm using version 11.0.0.116 of Toad for Oracle, connecting to Oracle 11.2.0.1.0
0
 
LVL 76

Expert Comment

by:slightwv (䄆 Netminder)
ID: 40352802
Try sqlplus.

I'm not a Toad person but it 'should be' able to fully understand sqlplus syntax.  Bug maybe?
0
 
LVL 29

Expert Comment

by:MikeOM_DBA
ID: 40353155
Also make sure the 'CALL' command has not been disabled (check  PRODUCT_USER_PROFILE table).
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 18

Author Comment

by:daveslash
ID: 40353533
Thanks for the suggestion, Mike. I can successfully CALL other stored procedures, so I'm pretty sure the command has not been disabled.

Also, I'm working on getting SQL-Plus access, so I can try slightwv's suggestion. (Thanks!)

Outside of what's already been suggested, what exactly IS the difference between CALL and EXEC ?
0
 
LVL 18

Author Comment

by:daveslash
ID: 40353537
ok, I checked:

select *
  from PRODUCT_USER_PROFILE
;

no rows selected.

Open in new window

0
 
LVL 76

Accepted Solution

by:
slightwv (䄆 Netminder) earned 500 total points
ID: 40353590
To be honest, I never heard of the CALL command until this question (or I forgot about it many years ago).

Maybe this will help but I doubt it.  To be honest, I'm not sure I understand the differences.

That said:
EXEC is in the sqlplus reference and CALL is in the SQL reference.  This tells me that one is supported by sqlplus and the other is supported by the SQL engine.



EXEC
where statement represents a PL/SQL statement.

Executes a single PL/SQL statement. The EXECUTE command is often useful when you want to execute a PL/SQL statement that references a stored procedure. For more information on PL/SQL, see your Oracle Database PL/SQL Language Reference.
http://docs.oracle.com/cd/E11882_01/server.112/e16604/ch_twelve022.htm#sthref1583

CALL
Purpose

Use the CALL statement to execute a routine (a standalone procedure or function, or a procedure or function defined within a type or package) from within SQL.
http://docs.oracle.com/cd/E11882_01/server.112/e41084/statements_4008.htm#sthref4053

>>Also, I'm working on getting SQL-Plus access

Instant client, two downloads (basic and sqlplus add on), no install, copy tnsnames.ora and you are good to go:
http://www.oracle.com/technetwork/database/features/instant-client/index-097480.html
0
 
LVL 18

Author Closing Comment

by:daveslash
ID: 40355954
That did it! Both EXEC and CALL worked beautifully from SQL-Plus.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Subquery in Oracle: Sub queries are one of advance queries in oracle. Types of advance queries: •      Sub Queries •      Hierarchical Queries •      Set Operators Sub queries are know as the query called from another query or another subquery. It can …
Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now