IF statement
The IF statement executes different sets of SQL statements based on the result of search conditions.
Syntax
Description
- label
Specifies the label for the IF statement. The label name cannot be the same as the routine name, advanced trigger name, or another label name within the same scope. For additional information, see References to SQL labels.
- search-condition
- Specifies the search-condition for which an SQL statement should be executed. If the condition is unknown or false, processing continues to the next search condition, until either a condition is true or processing reaches the ELSE clause.
- SQL-procedure-statement
- Specifies an SQL statement to be executed if the preceding search-condition is true. See SQL-procedure-statement (SQL PL).
Examples
Assign a value to the SQL variable new_salary based on the value of SQL variable rating.
IF rating = 1
THEN SET new_salary =
new_salary + (new_salary * .10);
ELSEIF rating = 2
THEN SET new_salary =
new_salary + (new_salary * .05);
ELSE SET new_salary =
new_salary + (new_salary * .02);
END IF;