1. Today, in Csdn, a question was observed:
CREATE OR REPLACE PACKAGE pkg_aa
As
TYPE Myrctype is REF CURSOR;
PROCEDURE Get (p_id number, p_rc out myrctype);
End Pkg_dept;
How do I call this stored procedure in Sql*plus? The main thing is not knowing to write that definition ref Cursor. Can you write an example of a call.
In addition, how to call it in the Pl/sql block.
2. My answer:
sql> CREATE OR REPLACE PACKAGE pkg_aa
2 AS
3 TYPE Myrctype is REF CURSOR;
4 PROCEDURE Get (p_id number, p_rc out myrctype);
5
6 End Pkg_aa;
7/
Package created
Sql>
sql> CREATE OR REPLACE PACKAGE Body "Pkg_aa" as
2
3 PROCEDURE Get (p_id number, p_rc out Myrctype)
4 is
5 V_num number;
6 BEGIN
7
8 SELECT p_id into v_num from dual;
9
OPEN P_RC for SELECT * from BasicCode;
11
End get;
13
14
15
End Pkg_aa;
17/
Package Body Created
Sql>
Sql> Declare
2 TYPE Myrctype is REF CURSOR;
3 Mycur Myrctype;
4 V_num number;
5 begin
6 Pkg_aa.get (v_num,mycur);
7 End;
8/
Pl/sql procedure successfully completed
3.Bobfang (hurried traveler) 's answer:
Called directly in Sqlplus, you can also do this
var c refcursor
EXEC pkg_aa.get (1,:C)
Print C
The results were successfully tested in Sqlplus.
I mainly use the command window in the Pl/sql devloper, also tried the Bobfang method, the implementation of Var C refcursor error:
sql> var c refcursor;
Refcursor not supported
sql> exec pkg_aa.get (1,:C)
Begin Pkg_aa.get (1,:C); End
Cursor Variable:c cannot be nil
C
---------
0
Sql> Print C
C
---------
0
So there is no test, it seems to be better to use Sqlplus to verify.