7th Example - CASE Selection on PL/SQL

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:

        Var1 NUMBER;
        Hasil VARCHAR2(16);
        Var1 := &nilai;
                        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);

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.

No comments

Powered by Blogger.