PLSQL - LOOP


LOOP:


LOOP
statements;
END LOOP;

EXIT:

There are two forms of the EXIT.
  • EXIT
  • EXIT-WHEN

LOOP
statements;
IF <condition> THEN
EXIT;   -- exit loop immediately
END IF;
END LOOP;


Example of Loop:

Declare
y number;
Begin
y :=  1;
Loop
dbms_output.put_line(y);
y := y + 2;
exit when y > 10;
End Loop;
End;

FOR LOOP

FOR <counter> IN [REVERSE]
lower_bound .. higher_bound LOOP
statements;
END LOOP

Example to print numbers from 1 to 10 using FOR Loop:

begin
for x in 1..10
Loop
dbms_output.put_line(x);
End Loop;
end;

Example to print numbers from 10 to 1 (in reverse) using FOR Loop:

Begin
for  index in REVERSE 1 ..10
Loop
dbms_output.put_line(index);
End Loop;
end;

Complete Tutorial

*/

No comments:

Post a Comment