Using NULLs in Comparisons
DECLARE
x NUMBER := 5;
y NUMBER := NULL;
BEGIN
IF x != y THEN -- yields NULL, not TRUE
dbms_output.Put_line('x != y'); -- not executed
ELSIF x = y THEN -- also yields NULL
dbms_output.Put_line('x = y');
ELSE
dbms_output.Put_line('Can''t tell if x and y are equal or not.');
END IF;
END;
/
In the following example, you might expect the sequence of statements to execute
because a and b seem equal. But, again, that is unknown, so the IF condition yields
NULL and the sequence of statements is bypassed.
DECLARE
a NUMBER := NULL;
b NUMBER := NULL;
BEGIN
IF a = b THEN -- yields NULL, not TRUE
dbms_output.Put_line('a = b'); -- not executed
ELSIF a != b THEN -- yields NULL, not TRUE
dbms_output.Put_line('a != b'); -- not executed
ELSE
dbms_output.Put_line('Can''t tell if two NULLs are equal');
END IF;
END;
/
0 comments:
Post a Comment