?
Solved

help with Oracle stored procedure with input and output parameters

Posted on 2014-09-30
8
Medium Priority
?
857 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:Dave Ford
[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:Dave Ford
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
Python: Series & Data Frames With Pandas

Learn the basics of Python’s pandas library of series & data frames and how we can use these tools for data manipulation.

 
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:Dave Ford
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:Dave Ford
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 2000 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:Dave Ford
ID: 40355954
That did it! Both EXEC and CALL worked beautifully from SQL-Plus.
0

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

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…
I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.
Suggested Courses

801 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