WHILE statement (Repeat statements)
Function
The WHILE statement executes repeatedly a set of SQL statements.
Format
[starting-label:]
WHILE search-condition DO
SQL-procedure-statement;[SQL-procedure-statement;]...
END [WHILE] [termination-label]
Operands
Specifies the starting label for the WHILE statement.
Specifies the condition under which the SQL procedure statements are to be executed repeatedly.
Specifies the SQL procedure statements that are to be executed repeatedly.
Specifies the end of the WHILE statement. Specify a statement label as a termination label.
The WHILE operand has the same effect whether or it is specified.
Common rules
AAA: WHILE X < 100 DO
BEGIN ...........................................1
DECLARE CN1 CONDITION FOR SQLCODE VALUE -800;
DECLARE EXIT HANDLER FOR CN1
AAA: BEGIN .........................................2
:
END AAA;
AAA: BEGIN .........................................3
DECLARE CN2 CONDITION FOR SQLCODE VALUE -800;
DECLARE EXIT HANDLER FOR CN2
:
END AAA;
SET X=X+1;
END
END WHILE AAA
Note
WHILE statements can be specified in an SQL routine.