Oracle PL/SQL - Variable Initialized to NULL by Default

Introduction

The following code shows that the variable counter has the initial value NULL, by default.

The example shows that NULL is different from zero.

Demo

SQL>
SQL> DECLARE-- from   w ww .  ja  v a  2  s  . c  om
  2    counter INTEGER;  -- initial value is NULL by default
  3  BEGIN
  4    counter := counter + 1;  -- NULL + 1 is still NULL
  5    DBMS_OUTPUT.PUT_LINE('counter'||TO_CHAR(counter));
  6
  7    IF counter IS NULL THEN
  8      DBMS_OUTPUT.PUT_LINE('counter is NULL.');
  9    END IF;
 10  END;
 11  /
counter
counter is NULL.

PL/SQL procedure successfully completed.

SQL>
SQL>

Related Topic