Was this helpful?
WHILE - ENDWHILE Example
In the following WHILE - ENDWHILE statement example, this database procedure, delete_n_rows, accepts as input a base number and a number of rows. The specified rows are deleted from the table “tab,” starting from the base number. If an error occurs, the loop terminates:
CREATE PROCEDURE delete_n_rows
      (base INTEGER, n INTEGER) AS
DECLARE
limit INTEGER;
      err INTEGER;
BEGIN
      limit = base + n;
      err = 0;
      WHILE (base < limit) DO
            DELETE FROM tab WHERE val = :base;
            IF iierrornumber > 0 THEN
                  err = 1;
                  ENDLOOP;
            ENDIF;
            base = base + 1;
      ENDWHILE;
      RETURN :err;
END
Last modified date: 08/14/2024