Rechercher dans le manuel MySQL
13.6.5.1 CASE Syntax
- CASE case_value
Or:
The CASE
statement for stored
programs implements a complex conditional construct.
There is also a CASE
expr, which differs from the
CASE
statement described here. See
Section 12.4, “Control Flow Functions”. The
CASE
statement cannot have an
ELSE NULL
clause, and it is terminated with
END CASE
instead of END
.
For the first syntax, case_value
is
an expression. This value is compared to the
when_value
expression in each
WHEN
clause until one of them is equal. When
an equal when_value
is found, the
corresponding THEN
clause
statement_list
executes. If no
when_value
is equal, the
ELSE
clause
statement_list
executes, if there is
one.
This syntax cannot be used to test for equality with
NULL
because NULL = NULL
is false. See Section 3.3.4.6, “Working with NULL Values”.
For the second syntax, each WHEN
clause
search_condition
expression is
evaluated until one is true, at which point its corresponding
THEN
clause
statement_list
executes. If no
search_condition
is equal, the
ELSE
clause
statement_list
executes, if there is
one.
If no when_value
or
search_condition
matches the value
tested and the CASE
statement
contains no ELSE
clause, a Case
not found for CASE statement error results.
Each statement_list
consists of one
or more SQL statements; an empty
statement_list
is not permitted.
To handle situations where no value is matched by any
WHEN
clause, use an ELSE
containing an empty
BEGIN ...
END
block, as shown in this example. (The indentation
used here in the ELSE
clause is for purposes
of clarity only, and is not otherwise significant.)
Document created the 26/06/2006, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/mysql-rf-case.html
The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.
References
These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author This site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.