1. Simple cycle
Loop
sequence of statements;
End Loop;
Cases:
Declare
a number:=100;
Begin
Loop
a:=a+25;
Exit when a=250;
End Loop;
Dbms_output.put_line (To_char (a));--note here with To_char ()
End
2.For Loop
For counter in [Reverse]lowerbound...upperbound
Loop
sequence of statements;
End Loop;
Counter is a counter variable, which is not declared here, and this variable can only be read in the loop body and cannot be assigned a value. If i++ is wrong.
Lowbound is the lower bound.
Upperbound is an upper bound, by default, iteration from the lower bound to the upper bound and, if the keyword reverse is used, the iteration from the upper bound to the lower bound
Cases:
Begin
For I in 1..2--if reversed, use the reverse keyword to
Loop
Update order_master set ostatus= ' P ' where odate<sysdate;
End Loop;
End
3.While Loop
while <condition>
Loop
sequence of statements;
End Loop;
Example:
Declare
i number:=0;
J number:=0;
Begin
while i<=100 loop
J:=j+i;
i:=i+2;
end Loop;
end;