Executes the first statement block whose condition is true.
The CFL If statement is similar to the CCL IF expression, but uses CFL components in its conditions and THEN, ELSEIF, and ELSE clauses, and is limited in scope according to the same rules as other CFL block statements.
The IF clause of the statement specifies a Boolean condition. If this condition is true, the block of statements after the first THEN clause are executed.
If the condition is false, the conditions of the ELSEIF clauses (if any are specified) are evaluated in sequence. The first of these conditions that evaluates to true causes the block of statements following the associated THEN clause to be executed.
If no ELSEIF clauses are used, or none of the Boolean conditions are true, the block of statements associated with the ELSE clause are executed, if one is specified.
If no ELSE clause exists and none of the Boolean conditions are true, no statements are executed.
Case Statement
The following example uses Return statements inside an If statement, resulting in a function that returns a value of -1, 0, or 1.
CREATE FUNCTION Compare(VALUE integer) RETURNS INTEGER IF ( value < 0 ) THEN RETURN -1; ELSEIF ( value = 0 ) THEN RETURN 0; ELSE RETURN 1; END IF; END FUNCTION;