Oracle PL/SQL - %ROWTYPE Variable Does Not Inherit Initial Values or Constraints

Introduction

The following code creates a table with two columns, each with an initial value and a NOT NULL constraint.

Then it declares a record variable that represents a row of the table and prints its fields.

From the result you can see that they did not inherit the initial values or NOT NULL constraints.

Demo

SQL>
SQL> DROP TABLE t1;
SQL> CREATE TABLE t1 (
  2    c1 INTEGER DEFAULT 0 NOT NULL,
  3    c2 INTEGER DEFAULT 1 NOT NULL
  4  );-- from  w  w w.  j  ava  2  s.  co m
SQL>
SQL> DECLARE
  2    t1_row t1%ROWTYPE;
  3  BEGIN
  4    DBMS_OUTPUT.PUT('t1.c1 = '); print(t1_row.c1);
  5    DBMS_OUTPUT.PUT('t1.c2 = '); print(t1_row.c2);
  6  END;
  7  /
t1.c1 = NULL
t1.c2 = NULL

PL/SQL procedure successfully completed.

SQL>
SQL>

Related Topic