CASE case_value WHEN when_value THEN statement [WHEN when_value THEN statement ...] [ELSE statement] END CASE
or
CASE WHEN search_condition THEN statement [WHEN search_condition THEN statement ...] [ELSE statement] END CASE
CASE
implements a complex conditional
construct. If a search_condition
evaluates
to true, the corresponding SQL statement is executed. If no
search condition matches, the statement in the
ELSE
clause is executed.
Please note that the syntax of a CASE
statement inside a stored procedure differs slightly from that
of the SQL CASE
expression. The
CASE
statement can not have an
ELSE NULL
clause, and the construct is
terminated with END CASE
instead of
END
. See
Secção 6.3.1.4, “Funções de Fluxo de Controle”.
This is a translation of the MySQL Reference Manual that can be found at dev.mysql.com. The original Reference Manual is in English, and this translation is not necessarily as up to date as the English version.