Oracle PL/SQL - NULL Value in Equal Comparison

Introduction

The IF condition yields NULL and the sequence of statements is bypassed.

Demo

SQL>
SQL> DECLARE-- from   w  ww.  j  a  v a2s  .com
  2    a NUMBER := NULL;
  3    b NUMBER := NULL;
  4  BEGIN
  5    IF a = b THEN                      -- yields NULL, not TRUE
  6      DBMS_OUTPUT.PUT_LINE('a = b');   -- not run
  7    ELSIF a != b THEN                  -- yields NULL, not TRUE
  8      DBMS_OUTPUT.PUT_LINE('a != b');  -- not run
  9    ELSE
 10      DBMS_OUTPUT.PUT_LINE('Can''t tell if two NULLs are equal');
 11    END IF;
 12  END;
 13  /
Can't tell if two NULLs are equal

PL/SQL procedure successfully completed.

SQL>
SQL>

Related Topic