oracle学习--循环语句

上一篇 / 下一篇  2010-12-22 17:16:05 / 个人分类:oracle

loop循环:
create or replace procedure pro_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 pro_test_loop;

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

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

for循环2:
create or replace procedure pro_test_cursor is
userRow t_user%rowtype;
cursor userRows is
select * from t_user;
begin
for userRow in userRows loop
    dbms_output.put_line(userRow.Id||','||userRow.Name||','||userRows%rowcount);
end loop;
end pro_test_cursor;

Exit When 也很方便:


Declare
p_SN int := 1;
Begin
Loop
Exit When (p_SN > 15);
DBMS_OUTPUT.PUT_LINE(p_SN);
p_SN := p_SN + 1;
End Loop;
End;


TAG:

 

评分:0

我来说两句

我的栏目

日历

« 2024-04-16  
 123456
78910111213
14151617181920
21222324252627
282930    

数据统计

  • 访问量: 6442
  • 日志数: 12
  • 建立时间: 2010-12-10
  • 更新时间: 2011-02-24

RSS订阅

Open Toolbar