ELSEIF is a control-flow keyword available in MySQL stored procedures, functions, triggers, and events. It lets you evaluate multiple mutually exclusive Boolean expressions without nesting separate IF blocks. Execution starts with the first IF condition; if it evaluates to TRUE the associated statement_list runs and execution jumps to END IF. If it is FALSE, control passes to the first ELSEIF. Each ELSEIF is checked in order. When a TRUE condition is found its statement_list runs and the block exits. If no IF or ELSEIF conditions match, the optional ELSE clause runs. Only one branch executes. ELSEIF may not be used in plain SQL outside stored program contexts. Different vendors spell the keyword differently (e.g., ELSIF in Oracle/PostgreSQL, ELSE IF in SQL Server) so portability requires care.
conditionX
(Boolean) - Expression that returns TRUE or FALSEstatement_listX
- SQL statements to execute when its condition is TRUEIF, CASE, LOOP, WHILE, ELSIF, BEGIN ... END
MySQL 4.0 (stored procedures became GA in 5.0)
Oracle and PostgreSQL spell the keyword ELSIF, while MySQL and MariaDB use ELSEIF. Functionally they are the same, but the spelling must match the dialect.
Yes. Multiple ELSEIF clauses flatten nested logic, making code easier to read and maintain.
In stored programs the overhead is negligible. MySQL evaluates conditions sequentially until one matches - early matches exit sooner.
The IF block ends without executing any statements. No error is raised.