SELECT Statement

The SELECT statement tests a series of expressions and performs the action specified with the first true test, or the action associated with the OTHERWISE clause (if present) and none of the tests evaluates true. Its general form is:

SELECT[select-expression];
    WHEN (e1[,e2[,e3[...]]])    action_1;
    WHEN (e4[,e5[,e6[...]]])    action_2;
       .
       .
       .
    [OTHERWISE action_m;] 
END;

where select-expression and e1, e2... are valid expressions, and each action is a single or compound statement or a BEGIN block. For example:

SELECT;
    WHEN (F=40) G=G+1;
    WHEN (F=50) IF G > 0 THEN G=G+2;
       .
       .
       .
    OTHERWISE DO;
              .
              .
              .
              END;
END;

This example shows the SELECT statement used with the expression omitted. When the expression is omitted from the SELECT statement, each WHEN clause expression is evaluated and converted, if necessary, to a bit string. The action after the WHEN clause is performed if the resulting bit string is nonzero. In the above example, if F=40 is true, the action G=G+1 is executed and the SELECT group is exited. If F=50 is true, the IF statement is executed and the SELECT group is exited. If more than one WHEN statement is true, the action associated with the first true WHEN clause is executed. If no WHEN clauses are true, the DO group associated with the OTHERWISE clause is executed.

When control reaches a SELECT statement with a select–expression present, the select-expression is evaluated and its value saved. Next, the expressions in the WHEN clauses are evaluated in the order in which they appear, and each value is compared with the value of select–expression. If a value is found that is equal to the value of select–expression, the action following the corresponding WHEN clause is performed, and no further WHEN clause expressions are evaluated. If none of the expressions in the WHEN clauses is equal to the select–expression, the action specified after the OTHERWISE clause is executed unconditionally. for more information, see the section SELECT in the chapter Statements.