Solved

help with Oracle stored procedure with input and output parameters

Posted on 2014-09-30
8
742 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
[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
  • 4
  • 3
8 Comments
 
LVL 77

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 77

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
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 
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
 
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 77

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

How to Create User-Defined Aggregates in Oracle Before we begin creating these things, what are user-defined aggregates?  They are a feature introduced in Oracle 9i that allows a developer to create his or her own functions like "SUM", "AVG", and…
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
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.

733 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