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!

Fetch into User defined type

InfoDocAug 10 2017 — edited Aug 11 2017

I have small/sample code below.

DECLARE

     CURSOR cusr IS select 'contract1', 111, sysdate from dual;

     TYPE recType IS RECORD(

           CONTRACT VARCHAR2(15),

           VENDNUM NUMBER, 

           LETTING_DATE DATE);

     vrec recType;

BEGIN

  OPEN cusr;

  LOOP

    FETCH cusr INTO vrec;

    EXIT WHEN cusr%NOTFOUND;

    dbms_output.put_line(vrec.contract||' '||to_char(vrec.letting_date,'YYYYMMDD'));

  END LOOP;

  CLOSE cusr;

END;

Can I INSTEAD, use the following custom pre-defined TYPE instead of the coded/bolded TYPE above?

create type CONT_TYPE as object(CONTRACT VARCHAR2(15), VENDNUM NUMBER, LETTING_DATE DATE);

My end state will be converting above code to a pipelined table function,

  but for now, I am simply trying to avoid typing the column definitions twice

This post has been answered by Solomon Yakobson on Aug 10 2017
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 8 2017
Added on Aug 10 2017
23 comments
2,225 views