8th Example - Odd Even on PL/SQL

Many programs that utilize odd even checking to solve various problems. Checking odd even in the PL/SQL block can be done by using IF condition operator or CASE condition operator coupled with the MOD function. Here is an example of checking odd even by using IF condition operator:

DECLARE
        Var1 NUMBER;
        Hasil VARCHAR2(16);
BEGIN
        Var1 := &n1;
        IF MOD(Var1, 2) = 0 THEN
                        Hasil := 'Genap';
        ELSE
                        Hasil := 'Ganjil';
        END IF;
        DBMS_OUTPUT.PUT_LINE (Hasil);
END;
/

If the substitution variable n1 given input value 10, then the output shown is "Genap". If the input value is 7, then the output is displayed is "Ganjil".

No comments

Powered by Blogger.