Oracle 循环语句

Exit When循环:

create or replace procedure proc_test_exit_when is
i number;
begin
i:=0;
LOOP
Exit When(i>5);
Dbms_Output.put_line(i);
i:=i+1;
END LOOP;
end proc_test_exit_when;

Loop循环:

create or replace procedure proc_test_loop is
i number;
begin
i:=0;
loop
i:=i+1;
dbms_output.put_line(i);
if i>5 then
exit;
end if;
end loop;
end proc_test_loop;

While循环:

create or replace procedure proc_test_while is
i number;
begin
i:=0;
while i<5 loop
i:=i+1;
dbms_output.put_line(i);
end loop;
end proc_test_while;

For循环:

create or replace procedure proc_test_for is
i number;
begin
i:=0;
for i in 1..5 loop
dbms_output.put_line(i);
end loop;
end proc_test_for;

For游标循环:

create or replace procedure proc_test_cursor is
userRow test%rowtype;
cursor userRows is
select * from test;
begin
for userRow in userRows loop
dbms_output.put_line(userRow.id||’,'||userRow.Name||’,'||userRows%rowcount);
end loop;
end proc_test_cursor;
原文地址:https://www.cnblogs.com/lichuangblog/p/6908039.html