Q:

Write a PL/SQL block to describe the usage of NULL values in equal comparison, unequal comparison and NOT NULL equals NULL comparison

0

Write a PL/SQL block to describe the usage of NULL values in equal comparison, unequal comparison and NOT  NULL equals NULL comparison.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now