Oracle PL/SQL - RECORD Type with RECORD Field (Nested Record)

Introduction

The following code defines two RECORD types, name_rec and contact. The type contact has a field of type name_rec.

Demo

SQL>
SQL> DECLARE--   ww  w.j  a  va 2s.  c o m
  2    TYPE name_rec IS RECORD(first emp.first_name%TYPE, last emp.last_name%TYPE);
  3    TYPE contact IS RECORD (name  name_rec,  -- nested record
  4      phone emp.phone_number%TYPE
  5    );
  6    friend contact;
  7  BEGIN
  8    friend.name.first := 'John';
  9    friend.name.last := 'Smith';
 10    friend.phone := '1-650-555-1234';
 11
 12    DBMS_OUTPUT.PUT_LINE(friend.name.first|| ' ' ||friend.name.last|| ', '||friend.phone
 13    );
 14  END;
 15  /

SQL>

Related Topic