Solved

help with Oracle stored procedure with input and output parameters

Posted on 2014-09-30
8
704 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

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…
Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
Via a live example, show how to take different types of Oracle backups using RMAN.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

786 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