IF Statement (Execute by conditional branching)
Function
The IF statement executes SQL statements that meet a given set of conditions.
Format
IF search-condition THEN SQL-procedure-statement;
[SQL-procedure-statement;]...
[ELSEIF search-condition THEN SQL-procedure-statement;
[SQL-procedure-statement;]...]
[ELSE SQL-procedure-statement;[SQL-procedure-statement;]...]
END IF
Operands
- IF search-condition THEN SQL-procedure-statement;[SQL-procedure-statement;] ...
- search-condition
- Specifies the conditions under which the SQL procedure statement specified in the THEN clause is executed.
- SQL-procedure-statement
- Specifies the SQL statement that is to be executed if the condition specified in the IF clause is met.
- [ELSEIF search-condition THEN SQL-procedure-statement;[SQL-procedure-statement;] ...]
- search-condition
- Specifies the conditions under which the SQL procedure statement specified in the THEN clause is executed.
- SQL-procedure-statement
- Specifies the SQL statement that is to be executed if the condition specified in the IF clause is not met but the condition specified in the ELSEIF clause is met.
- [ELSE SQL-procedure-statement; [SQL-procedure-statement;] ...]
- SQL-procedure-statement
- Specifies the SQL statement that is to be executed if the conditions specified in the IF and ELSEIF clauses are not met.
Specifies the end of the IF statement.
Common rules
- SQL procedure statements are executed in the order in which they are specified. If an error occurs during the execution of an SQL procedure statement, any subsequent SQL procedure statements will not be executed.
- A subquery cannot be specified in a search condition.
Note
IF statements can be specified in an SQL routine.