CASE WHEN

When constructing the body of an SQL procedure, you can use the CASE WHEN statement to perform one or more actions based on a condition. If the condition is not met, you can optionally perform a different action.

Syntax

CASE
  WHEN condition THEN action_command_list
  ...
 [ ELSE action_command_list ]
END CASE;

If the first condition is met (evaluates to TRUE), the statements following the THEN keyword are run in sequence until a WHEN, ELSE, or END CASE is reached. Otherwise, if there is any WHEN statement for which the condition is met, the statements following the THEN keyword are run until a WHEN, ELSE, or END CASE is reached. If no previous condition is met and there is an ELSE statement, the statements following the ELSE statement are run until an END CASE statement is reached.