Oracle PL/SQL - Assigning Nested Record to Another Record of Same RECORD Type

Introduction

The following code assigns the value of one nested record to another nested record.

The nested records have the same RECORD type, but the records in which they are nested do not.

Demo

SQL>
SQL> DECLARE-- www  .j av a 2 s .  co  m
  2    TYPE name_rec IS RECORD (
  3      first  emp.first_name%TYPE,
  4      last   emp.last_name%TYPE
  5    );
  6
  7    TYPE phone_rec IS RECORD (
  8      name  name_rec,  -- nested record
  9      phone emp.phone_number%TYPE
 10    );
 11
 12    TYPE email_rec IS RECORD (
 13      name  name_rec,  -- nested record
 14      email emp.email%TYPE
 15    );
 16
 17    phone_contact phone_rec;
 18    email_contact email_rec;
 19
 20  BEGIN
 21    phone_contact.name.first := 'John';
 22    phone_contact.name.last := 'Smith';
 23    phone_contact.phone := '1-650-555-1234';
 24
 25    email_contact.name := phone_contact.name;
 26    email_contact.email := (
 27      email_contact.name.first || '.' ||
 28      email_contact.name.last  || '@' ||
 29      'example.com'
 30    );
 31
 32    DBMS_OUTPUT.PUT_LINE (email_contact.email);
 33  END;
 34  /


SQL>

Related Topic