Executes one or more SQL statements conditionally. It then
continues processing by executing any SQL statement that
immediately follows the block.
1 – Environment
You can use the IF control statement in a compound statement:
o In interactive SQL
o Embedded in host language programs to be precompiled
o As part of a procedure in an SQL module
o In dynamic SQL as a statement to be dynamically executed
2 – Format
(B)0[m[1mif-statement = [m [1m [m [1mqqqqq> [1;4mIF[m[1m predicate [1;4mTHEN[m[1m qqwq> compound-use-statement qwqqqqqqqqk [m [1m mqqqqqqqqqqqq <qqqqqqqqqqqqqj x [m [1mlqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj [m [1mmwqwqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqwqwqk [m [1m x mq> [1;4mELSEIF[m[1m predicate [1;4mTHEN[m[1m qwq> compound-use-statement qwqj x x [m [1m x mqqqqqqqqqqqq <qqqqqqqqqqqqqj x x [m [1m mqqqqqqqqqqqqqqqqqqqqqqqqqqqq <qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj x [m [1mlqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj [m [1mmqqwqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqwqq> [1;4mEND[m[1m [1;4mIF[m[1m qqqqqqqqq> [m [1m mq> [1;4mELSE[m[1m qqwq> compound-use-statement qwqj [m [1m mqqqqqqqqqqqq <qqqqqqqqqqqqqj [m [1m [m
3 – Arguments
3.1 – compound-use-statement
See the Compound_Statement HELP topic for a description of the
SQL statements that are valid in a compound statement.
3.2 – END_IF
Marks the end of an IF statement. Every IF statement must end
with the END IF clause.
3.3 – ELSE compound use statement
Executes one or more SQL statements associated with the ELSE
clause but only when the value of the IF and ELSEIF predicates
evaluate to FALSE or UNKNOWN.
3.4 – ELSEIF_THEN
If the ELSEIF predicate evaluates to TRUE, SQL executes the SQL
statements in the THEN clause. If the ELSEIF predicate does not
evaluate to TRUE, SQL evaluates the predicates in any subsequent
ELSEIF or ELSE clauses.
3.5 – IF_THEN
Executes one or more SQL statements in an IF . . . END IF block
only when the value of an IF predicate evaluates to TRUE. A
predicate, also called a conditional expression, specifies a
condition that SQL evaluates to TRUE, FALSE, or UNKNOWN. If
the predicate evaluates to TRUE, SQL executes the statement in
the THEN clause. If the predicate does not evaluate to TRUE,
SQL evaluates the predicate in any ELSEIF clauses. If the IF
statement contains no ELSEIF clauses, SQL executes any statements
in the ELSE clause.
3.6 – predicate
See the Predicates HELP topic for more information on predicates.
4 – Examples
Example 1: Using an IF control statement
IF (SELECT COUNT (*) FROM STUDENTS
WHERE CLASS = :CLASS_NUM)
> 30
THEN
SET :MSG = 'Class is too large.';
ELSE
SET :MSG = 'Class size is O.K.';
END IF;