Oracle SQL,PL/SQL

Oracle PL/SQL Loop: Basic Loop, While Loop ,For Loop and Continue Statement

Oracle PLSQL Loop
Written by shohal

Oracle PL/SQL Loop Structure and Example

Basic Loop Structure :

DECLARE
X NUMBER:=0;
BEGIN
Loop
x:=x+1;
exit when x>=5;
dbms_output.put_line(x);
end loop;
END;

Output:

1
2
3
4

While Loop Structure:

Declare
x number:=0;
begin
while x<=5 loop
x:=x+1;
dbms_output.put_line(x);
end loop;
end;

Output :

1
2
3
4
5
6

For Loop Structure :

 Declare
 x number:=0;
 begin
 for x in 1..5 loop
 dbms_output.put_line(x);
 end loop;
 end;

Output:

1
2
3
4
5

Continue Statement Structure :

 Declare
 x number:=0;
 begin
 for x in 1..5 loop
 if x=1 then
 continue;
 end if;
 dbms_output.put_line(x);
 end loop;
 end;

Output :

2
3
4
5

About the author

shohal