Oracle PL/SQL - NULL Value in Unequal Comparison

Introduction

NULL values are indeterminate.

Whether x equals y is unknown.

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

Demo

SQL>
SQL> DECLARE--  w w w .  j a v  a2  s.  co m
  2    x NUMBER := 5;
  3    y NUMBER := NULL;
  4  BEGIN
  5    IF x != y THEN                     -- yields NULL, not TRUE
  6      DBMS_OUTPUT.PUT_LINE('x != y');  -- not run
  7    ELSIF x = y THEN                   -- also yields NULL
  8      DBMS_OUTPUT.PUT_LINE('x = y');
  9    ELSE
 10      DBMS_OUTPUT.PUT_LINE ('Can''t tell');
 11    END IF;
 12  END;
 13  /
Can't tell.

PL/SQL procedure successfully completed.

SQL>
SQL>

Related Topic