Friday, June 7, 2013

7th Example - CASE Selection on PL/SQL

Leave a Comment
CASE WHEN is another types of selection operator rather than IF in PL/SQL block. Here is an example of PL/SQL block that has the CASE operator WHEN:


DECLARE
        Var1 NUMBER;
        Hasil VARCHAR2(16);
BEGIN
        Var1 := &nilai;
        CASE
                        WHEN Var1>=70 THEN Hasil := 'Great';
                        WHEN Var1>=60 AND Var1<70 THEN Hasil := 'Good';
                        ELSE Hasil := 'Poor';
        END CASE;
        DBMS_OUTPUT.PUT_LINE (Hasil);
END;
/

WHEN command is used to check for certain conditions, if the conditions are not met then it will check the next condition. If all the conditions do not exist that meet then the ELSE will be the last option.
If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment