[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1063
  • Last Modified:

help with Oracle stored procedure with input and output parameters

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
Dave Ford
Asked:
Dave Ford
  • 4
  • 3
1 Solution
 
slightwv (䄆 Netminder) Commented:
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
 
Dave FordSoftware Developer / Database AdministratorAuthor Commented:
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
 
slightwv (䄆 Netminder) Commented:
Try sqlplus.

I'm not a Toad person but it 'should be' able to fully understand sqlplus syntax.  Bug maybe?
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
MikeOM_DBACommented:
Also make sure the 'CALL' command has not been disabled (check  PRODUCT_USER_PROFILE table).
0
 
Dave FordSoftware Developer / Database AdministratorAuthor Commented:
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
 
Dave FordSoftware Developer / Database AdministratorAuthor Commented:
ok, I checked:

select *
  from PRODUCT_USER_PROFILE
;

no rows selected.

Open in new window

0
 
slightwv (䄆 Netminder) Commented:
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
 
Dave FordSoftware Developer / Database AdministratorAuthor Commented:
That did it! Both EXEC and CALL worked beautifully from SQL-Plus.
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now