Mega Code Archive

 
Categories / Oracle PLSQL / PL SQL
 

NVL deals with a boolean expression

SQL> SQL> --  Effects of nulls on boolean expressions. SQL> SET SERVEROUTPUT ON SQL> SQL> DECLARE   2     a     INTEGER;   3     n     INTEGER;     -- be our null value.   4  BEGIN   5     -- Assign a value to the variable A, but leave N null.   6     a := 2;   7     -- TIP: try this if you want a null value to be considered "not equal".   8     -- Be careful though, if BOTH A and N are NULL NVL will still return TRUE.   9     IF NVL((a <> n),true) THEN  10       DBMS_OUTPUT.PUT_LINE('The values are not equal.');  11     ELSE  12       DBMS_OUTPUT.PUT_LINE('The values are equal.');  13     END IF;  14     -- TIP: a three-valued IF construct.  15  END;  16  / The values are not equal. PL/SQL procedure successfully completed. SQL>