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: 11/09/2022