A call that contains the procedure for the cursor type in the package!

Source: Internet
Author: User
Tags sqlplus

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.