Oracle PL/SQL/PL SQL/Not Null Variable

Материал из SQL эксперт
Перейти к: навигация, поиск

Declare not null variable

SQL>
SQL> -- declare not null variable
SQL>
SQL>  declare
  2      l_number number not null := 1;
  3      l_another_number number;
  4    begin
  5      l_number := 2;
  6      l_number := l_another_number;
  7    end;
  8    /
 declare
*
ERROR at line 1:
ORA-06502: PL/SQL: numeric or value error
ORA-06512: at line 6

SQL>



NOT NULL specification which means you must initialize it

SQL>
SQL> -- NOT NULL specification which means you must initialize it (otherwise, it gets the default value of NULL).
SQL>
SQL> set serverout on;
SQL>
SQL> DECLARE
  2     X NUMBER NOT NULL := 20;
  3
  4  BEGIN
  5
  6
  7     DBMS_OUTPUT.PUT_LINE(x);
  8
  9  END;
 10
 11
 12  /
20
PL/SQL procedure successfully completed.
SQL>