DECLARE
m NUMBER := 7;
n NUMBER := NULL;
o NUMBER := NULL;
p NUMBER := NULL;
q INTEGER := 4;
r INTEGER := 9;
large INTEGER;
----------------------------------
BEGIN
IF m != n THEN -- yields NULL, not TRUE
DBMS_OUTPUT.PUT_LINE('m != n'); -- not run
ELSIF m = n THEN -- also yields NULL
DBMS_OUTPUT.PUT_LINE('m = n');
ELSE
DBMS_OUTPUT.PUT_LINE
('Can not say whether m and n are equal or not.');
END IF;
-----------------------------------
IF o = p THEN -- yields NULL, not TRUE
DBMS_OUTPUT.PUT_LINE('o = p'); -- not run
ELSIF o != p THEN -- yields NULL, not TRUE
DBMS_OUTPUT.PUT_LINE('o != p'); -- not run
ELSE
DBMS_OUTPUT.PUT_LINE('Can not say whether two NULLs are equal');
END IF;
--------------------------------------
IF (q > r) -- If q or r is NULL, then (q > r) is NULL
THEN large := q; -- run if (q > r) is TRUE
ELSE large := r; -- run if (q > r) is FALSE or NULL
DBMS_OUTPUT.PUT_LINE('The value of large : '||large);
END IF;
IF NOT (q > r) -- If q or r is NULL, then NOT (q > r) is NULL
THEN large := r; -- run if NOT (q > r) is TRUE
ELSE large := q; -- run if NOT (q > r) is FALSE or NULL
DBMS_OUTPUT.PUT_LINE('The value of large : '||large);
END IF;
END;
/
Sample Output:
Can not say whether m and n are equal or not.
Can not say whether two NULLs are equal
The value of large : 9
Statement processed.
0.00 seconds
Sample Output:
need an explanation for this answer? contact us directly to get an explanation for this answer