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 you want to execute a certain section of code only if a condition is true, you can use an IF-THEN statement.

IF condition THEN
   -- statements
END IF;

IF-THEN-ELSIF Statement

You can also use an IF-THEN-ELSIF statement to check multiple conditions.

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

IF-THEN-ELSE Statement

If you want to execute a certain section of code only if a condition is NOT true, you can use an IF-THEN-ELSE statement.

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

CASE Statement

You can use the CASE statement to select one of several alternative sections of code to execute.

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;