Oracle 11G provides new feature for the loops calling CONTINUE.
This statment allows to exit the loop if CONTINUE is passing with out any conditions or skip loop iteration and gows to the next one when the contition is met.
Here is a very simple examle for printing the numbers from 1 to 10 which are not devided by 2
begin
This statment allows to exit the loop if CONTINUE is passing with out any conditions or skip loop iteration and gows to the next one when the contition is met.
Here is a very simple examle for printing the numbers from 1 to 10 which are not devided by 2
begin
for i in 1..10 loop
continue when mod(i,2)=0;
dbms_output.put_line(i);
end loop;
end;
Here is the same code but without a WHEN statment in continue
begin
for i in 1..10 loop
if mod(i,2)=0 then continue;end if;
dbms_output.put_line(i);
end loop;
end;
Umfortunatelly 10G is not supoort CONTINUE but we can rewrite it using GOTO and labels
declare
i integer default 0;
begin
while i<9 loop
<<mylabel>>
i:=i+1;
if mod(i,2)=0 then goto mylabel;end if;
dbms_output.put_line(i);
end loop;
end;
Комментариев нет:
Отправить комментарий