Oracle Conditional Statements

Oracle Conditional Statements

The Oracle conditional statements are IF and CASE.

IF THEN Statement

IF condition THEN
  --SQL, PL/SQL statements
END IF;

IF THEN ELSE Statement

IF condition THEN
  --SQL, PL/SQL statements
ELSE
  --SQL, PL/SQL statements
END IF;

IF THEN ELSIF Statement

IF condition_A THEN
  --SQL, PL/SQL statements A
ELSIF condition_B THEN
  --SQL, PL/SQL statements B
ELSIF condition_C THEN
  --SQL, PL/SQL statements C
ELSE
  --SQL, PL/SQL statements
END IF;

Simple CASE Statement

CASE selector
WHEN selector_value_a THEN statements_a
WHEN selector_value_b THEN statements_b
WHEN selector_value_c THEN statements_c
...
WHEN selector_value_n THEN statements_n
[ ELSE
  else_statements ]
END CASE;]

Searched CASE Statement

CASE
WHEN condition_a THEN statements_a
WHEN condition_b THEN statements_b
WHEN condition_c THEN statements_c
...
WHEN condition_n THEN statements_n
[ ELSE
  else_statements ]
END CASE;]