Rechercher dans le manuel MySQL
13.6.5.2 IF Syntax
The IF
statement for stored
programs implements a basic conditional construct.
There is also an IF()
function, which differs from the
IF
statement described here. See
Section 12.4, “Control Flow Functions”. The
IF
statement can have
THEN
, ELSE
, and
ELSEIF
clauses, and it is terminated with
END IF
.
If a given search_condition
evaluates
to true, the corresponding THEN
or
ELSEIF
clause
statement_list
executes. If no
search_condition
matches, the
ELSE
clause
statement_list
executes.
Each statement_list
consists of one
or more SQL statements; an empty
statement_list
is not permitted.
An IF ... END IF
block, like all other
flow-control blocks used within stored programs, must be
terminated with a semicolon, as shown in this example:
- DELIMITER //
- RETURN s;
- END //
- DELIMITER ;
As with other flow-control constructs, IF ... END
IF
blocks may be nested within other flow-control
constructs, including other IF
statements. Each IF
must be
terminated by its own END IF
followed by a
semicolon. You can use indentation to make nested flow-control
blocks more easily readable by humans (although this is not
required by MySQL), as shown here:
- DELIMITER //
- RETURN s;
- END //
- DELIMITER ;
In this example, the inner IF
is
evaluated only if n
is not equal to
m
.
Document created the 26/06/2006, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/mysql-rf-if.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.