Oracle PL/SQL - Assigning %ROWTYPE Record to RECORD Type Record

Description

Assigning %ROWTYPE Record to RECORD Type Record

Demo

SQL>
SQL> drop TABLE emp;

Table dropped.--   w  w  w  . ja  va2  s . co m

SQL>
SQL> CREATE TABLE emp(
  2  empid NUMBER(6),
  3  first_name VARCHAR2(20),
  4  last_name VARCHAR2(25)) ;
SQL>
SQL> DECLARE
  2    TYPE name_rec IS RECORD (
  3      first  emp.first_name%TYPE DEFAULT 'John',
  4      last   emp.last_name%TYPE DEFAULT 'Doe'
  5    );
  6
  7    CURSOR c IS SELECT first_name, last_name FROM emp;
  8
  9    target name_rec;
 10    source c%ROWTYPE;
 11
 12  BEGIN
 13    source.first_name := 'Jane'; source.last_name := 'Smith';
 14
 15    DBMS_OUTPUT.PUT_LINE('source: ' || source.first_name || ' ' || source.last_name);
 16
 17    target := source;
 18
 19    DBMS_OUTPUT.PUT_LINE('target: ' || target.first || ' ' || target.last);
 20  END;
 21  /
source: Jane Smith
target: Jane Smith

PL/SQL procedure successfully completed.

SQL>

Related Topic