Behaviour of NULL’s

0
 
Behaviour of NULL’s:
  • In simple “IF” when a condition is evaluated to NULL, then the statements in “TRUE” state will not be executed, instead the control will be passed to the first executable statement after the “END IF”.
  • In IF…THEN…ELSE construct the FALSE block is executed whenever the condition evaluates to NULL.
  • Hence when ever a conditional process is executed it is better to cross verify the NULL status of any variable or value before execution.
SQL> DECLARE
        v_Firstnum NUMBER:=&Fnum;
        v_Secondnum NUMBER:=&Snum;
    BEGIN
    IF v_Firstnum=v_Secondnum THEN
    DBMS_OUTPUT.PUT_LINE(‘Given numbers are equal’);
        END IF;
    DBMS_OUTPUT.PUT_LINE(‘Did you watch the NULL effect.’);
    END;

Note: Supply NULL at runtime to check the effect of NULL


SQL> DECLARE
        v_num NUMBER:=&Enternumber;
    BEGIN
    IF MOD(v_num,2)=0 THEN
    DBMS_OUTPUT.PUT_LINE(‘v_num||’is an Even number.’);
    ELSE
    DBMS_OUTPUT.PUT_LINE(‘v_num||’is an Odd number.’);
        END IF;
    DBMS_OUTPUT.PUT_LINE(‘Did you watch the Difference….’);
    END;


 Click here to go to Back page

About the author

Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus, neque id cursus faucibus. Aenean fermentum, eget tincidunt.

0 comments:

Recent Posts