1、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;
--结果:0 1 2 3 4 5
2、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;
--结果:1 2 3 4 5 6
3、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;
--结果:1 2 3 4 5
4、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;
--结果:1 2 3 4 5
5、For游标循环:
create or replace procedure proc_test_cursor is
userRow test_user_t%rowtype;
cursor userRows is
select * from test_user_t;
begin
for userRow in userRows loop
dbms_output.put_line('用户ID:'||userRow.user_id||' 用户名:'||userRow.user_name||' 行号:'||userRows%rowcount);
end loop;
end proc_test_cursor;