PLSQL Language Referenc-PL/SQL控制語句-條件選擇語句-IF THEN ELSE

LuiseDalian發表於2014-03-09

IF 條件 THEN

    語句;

ELSE

    語句;

END IF;


 

DECLARE

    PROCEDURE p (

        sales  NUMBER,

        quota  NUMBER,

        emp_id NUMBER

    )

    IS

        bonus  NUMBER := 0;

    BEGIN

        IF sales > (quota + 200) THEN

            bonus := (sales - quota)/4;

        ELSE

            bonus := 50;

        END IF;

 

        DBMS_OUTPUT.PUT_LINE('獎金 = ' || bonus);

 

        UPDATE employees

        SET salary = salary + bonus

        WHERE employee_id = emp_id;

    END p;

BEGIN

    p(10100, 10000, 120);

    p(10500, 10000, 121);

END;

 


 

--巢狀的IF THEN ELSE

DECLARE

    PROCEDURE p (

        sales  NUMBER,

        quota  NUMBER,

        emp_id NUMBER

    )

    IS

        bonus  NUMBER := 0;

    BEGIN

        IF sales > (quota + 200) THEN

            bonus := (sales - quota)/4;

        ELSE

            IF sales > quota THEN

                bonus := 50;

            ELSE

                bonus := 0;

            END IF;

        END IF;

 

        DBMS_OUTPUT.PUT_LINE('獎金 = ' || bonus);

 

        UPDATE employees

        SET salary = salary + bonus

        WHERE employee_id = emp_id;

  END p;

BEGIN

    p(10100, 10000, 120);

    p(10500, 10000, 121);

    p(9500, 10000, 122);

END;

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/17013648/viewspace-1104116/,如需轉載,請註明出處,否則將追究法律責任。

相關文章