FOR

When constructing the body of an SQL procedure, you can use the FOR loop to perform actions a set number of times, based on a counter variable.

Syntax

FOR counter = 1 to integer DO
 BEGIN
   action_command_list;
END;

A BREAK command exits from the current loop, and the next statement in the procedure starts to run.

A CANCEL command stops the running of a procedure.

Attention: Do not use the CANCEL command when using a desktop ObjectServer in DualWrite mode.

Example

The following procedure updates each row of the alerts.status table and sets the acknowledged flag to TRUE:

CREATE PROCEDURE ACKNOWLEDGE_TOOL( ids ARRAY OF CHAR(255) )
 DECLARE
   k INTEGER;
 BEGIN
   FOR k = 1 TO array_len( ids ) DO
   BEGIN
    UPDATE alerts.status VIA ( ids[k] ) SET Acknowledged = TRUE;
   END;
END;