The following SPL routine uses an IF - ELIF - ELSE structure
to compare the two arguments that the routine accepts.
Suppose you define a table named manager with
the columns that the following figure shows.
The following SPL routine uses an IF - ELIF - ELSE structure
to check the number of elements in the SET in the direct_reports column
and call various external routines based on the results.
The cardinality() function counts
the number of elements that a collection contains. For more information,
see Cardinality function.
An IF
- ELIF - ELSE structure in an SPL routine has up to the following
four parts:
An IF THEN condition
If the condition following the IF statement
is TRUE, the routine executes the statements in the IF block. If the
condition is false, the routine evaluates the ELIF condition.
The
expression in an IF statement can be any valid condition, as the Condition
segment of the HCL OneDB™ Guide to SQL:
Syntax describes.
For the complete syntax and a detailed discussion of the IF statement,
see the HCL OneDB Guide to SQL:
Syntax.
One or more ELIF conditions (optional)
The routine evaluates
the ELIF condition only if the IF condition is false. If the ELIF
condition is true, the routine executes the statements in the ELIF
block. If the ELIF condition is false, the routine either evaluates
the next ELIF block or executes the ELSE statement.
An ELSE condition (optional)
The routine executes the statements
in the ELSE block if the IF condition and all of the ELIF conditions
are false.