PL/SQL Control Structures

The IF-THEN statement of PL/SQL language has the same structure as the others equivalent procedural languages​​. The IF-THEN statement allows selective execution of actions based on the fulfillment of certain conditions.

IF-THEN Statement

IF condition THEN
   -- statements
END IF;

IF-THEN-ELSIF Statement

IF condition_1 THEN
   -- statement_1
ELSIF condition_2 THEN
   -- statement_2
END IF;

IF-THEN-ELSE Statement

IF condition_1 THEN
   -- statement_1
ELSIF condition_2 THEN
   -- statement_2
ELSE
   -- statement_3
END IF;

CASE Statement

CASE expression
   WHEN condition_1 THEN statement_1;
   WHEN condition_2 THEN statement_2;
   WHEN condition_3 THEN statement_3;
   ELSE statement_4;
END CASE;

Examples