Oracle PL/SQL - IF THEN ELSIF Statement

Introduction

The IF THEN ELSIF statement has this structure:

IF condition_1 THEN 
  statements_1 
ELSIF condition_2 THEN 
  statements_2 
 [ ELSIF condition_3 THEN 
    statements_3 
]... 
 [ ELSE 
    else_statements 
] 
END IF; 

The IF THEN ELSIF statement runs the first statements for which condition is true.

Remaining conditions are not evaluated.

If no condition is true, the else_statements run, if they exist; otherwise, the IF THEN ELSIF statement does nothing.

Demo

SQL>
SQL> DECLARE--   ww w. j  a  v a2  s  .com
  2    PROCEDURE p (sales NUMBER)
  3    IS
  4      bonus  NUMBER := 0;
  5    BEGIN
  6      IF sales > 50000 THEN
  7        bonus := 1500;
  8      ELSIF sales > 35000 THEN
  9        bonus := 500;
 10      ELSE
 11        bonus := 100;
 12      END IF;
 13
 14      DBMS_OUTPUT.PUT_LINE('Sales = ' || sales || ', bonus = ' || bonus || '.');
 15    END p;
 16  BEGIN
 17    p(55000);
 18    p(40000);
 19    p(30000);
 20  END;
 21  /
Sales = 55000, bonus = 1500.
Sales = 40000, bonus = 500.
Sales = 30000, bonus = 100.

PL/SQL procedure successfully completed.

SQL>

Related Topic