Simple CASE statement with range : CASE « PL SQL Statements « Oracle PL/SQL Tutorial






SQL> DECLARE
  2    salary NUMBER := 20000;
  3    employee_id NUMBER := 36325;
  4
  5    PROCEDURE give_bonus (emp_id IN NUMBER, bonus_amt IN NUMBER) IS
  6    BEGIN
  7      DBMS_OUTPUT.PUT_LINE(emp_id);
  8      DBMS_OUTPUT.PUT_LINE(bonus_amt);
  9    END;
 10
 11  BEGIN
 12  CASE TRUE
 13  WHEN salary >= 10000 AND salary <=20000 THEN
 14     give_bonus(employee_id, 1500);
 15  WHEN salary > 20000 AND salary <= 40000 THEN
 16     give_bonus(employee_id, 1000);
 17  WHEN salary > 40000 THEN
 18     give_bonus(employee_id, 500);
 19  ELSE
 20     give_bonus(employee_id, 0);
 21  END CASE;
 22  END;
 23  /

PL/SQL procedure successfully completed.

SQL>
SQL>
SQL>








22.2.CASE
22.2.1.CASE statements
22.2.2.When creating selector CASE statements, you cannot have NULL in the list of possible values.
22.2.3.Use CASE statement
22.2.4.Named case block
22.2.5.case when
22.2.6.An example of comparison of two numbers using a searched CASE expression
22.2.7.Variable assignment with case statement
22.2.8.Use case statement in a dbms_output.put_line
22.2.9.Simple CASE statement with range
22.2.10.Case statement to call procedure
22.2.11.Return statement with case
22.2.12.Use case statement in procedure call to use the proper parameter value