Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to use record type as an OUT parameter in PL/SQL proc or package

1018539Jun 21 2013 — edited Jun 24 2013

Hi Folks,

I would need some assistance on record type as an OUT parameter.I am able to take a single row as out parameter but not getting idea how to get multi rows as an out parameter.

I have following code which works fine for single row. Please refer CODE1.

But when i try to get multiple rows i am failing to do so. Please refer the CODE2. I get compilation error as


Error report:

ORA-06550: line 11, column 35:

PLS-00487: Invalid reference to variable 'P_NAME'

ORA-06550: line 11, column 1:

PL/SQL: Statement ignored

06550. 00000 -  "line %s, column %s:\n%s"

*Cause:    Usually a PL/SQL compilation error.

Any assistance or a sample running script would be really helpful.

Thanks In Advance.

YZ

--------------------------CODE1------------------------------------------

-------------------------Package Spec-------------------------------

CREATE OR REPLACE

PACKAGE xx_sample_pkg as

--

TYPE xx_sample_table_rectype IS RECORD

                                                                ( p_name varchar2(40),         

                                                                  p_emp_id number

                                                                );

PROCEDURE xx_sample_prc(xx_sample_rec1 OUT xx_sample_table_rectype);

END xx_sample_pkg;

------------------------------Package Body------------------------

create or replace

PACKAGE BODY xx_sample_pkg AS

--

PROCEDURE xx_sample_prc(xx_sample_rec1 OUT xx_sample_table_rectype)IS

BEGIN

SELECT ename,empno

INTO xx_sample_rec1

FROM scott.emp

WHERE ename='SMITH';

END xx_sample_prc;

END xx_sample_pkg ;

-------------------------------------------Execute----------------------

DECLARE

l_rec_type xx_sample_pkg.xx_sample_table_rectype;

BEGIN

dbms_output.put_line(' calling xx_sample_prc ');

xx_sample_pkg.xx_sample_prc(l_rec_type);

dbms_output.put_line('YZ '||l_rec_type.p_name||' '||l_rec_type.p_emp_id);

END;

---------------------------------------------------------------

-------------------------CODE2-------------------------------------------

-------------------------Package Spec-------------------------------

CREATE OR REPLACE

PACKAGE xx_sample_pkg as

--

TYPE xx_sample_table_rectype IS RECORD

                                                                ( p_name varchar2(40),         

                                                                  p_emp_id number

                                                                );

PROCEDURE xx_sample_prc(xx_sample_rec1 OUT xx_sample_table_rectype);

END xx_sample_pkg;

------------------------------Package Body------------------------

create or replace

PACKAGE BODY xx_sample_pkg AS

--

PROCEDURE xx_sample_prc(xx_sample_rec1 OUT xx_sample_table_rectype)IS

BEGIN

SELECT ename,empno

INTO xx_sample_rec1

FROM scott.emp;

END xx_sample_prc;

END xx_sample_pkg ;

-------------------------------------------Execute----------------------

DECLARE

l_rec_type xx_sample_pkg.xx_sample_table_rectype;

BEGIN

dbms_output.put_line(' calling xx_sample_prc ');

xx_sample_pkg.xx_sample_prc(l_rec_type);

for l_rec in 1..l_rec_type.p_name.count

loop

dbms_output.put_line('YZ '||l_rec_type.p_name(l_rec)||' '||l_rec_type.p_emp_id(l_rec));

end loop;

end;

---------------------------------------------------------------

This post has been answered by Solomon Yakobson on Jun 23 2013
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 22 2013
Added on Jun 21 2013
13 comments
14,527 views