Was this helpful?
REPEAT - ENDREPEAT Example
In the following REPEAT - ENDREPEAT 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. Because this is a repeat loop, one row will always be deleted. If it is possible for no rows to be identified, the pre-testing WHILE – ENDWHILE loop should be used instead. 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;
      repeat
            delete from tab where val = :base;
            if iierrornumber > 0 then
                  err = 1;
                  endloop;
            endif;
            base = base + 1;
      until (base < limit) endrepeat;
      return :err;
end
Last modified date: 08/29/2024