您的位置:首页 > 数据库 > Oracle

[Oracle] 循环的几种方式

2017-10-06 00:00 253 查看
-- goto
declare
x number;
begin
x:=9;
<<repeat_loop>>
x:=x-1;
dbms_output.put_line('x: '||x);
if x>0 then
goto repeat_loop;
end if;
end;

-- for
declare
x number;
begin
x:=1;
for x in reverse 1..10 loop
dbms_output.put_line('x: '||x);
end loop;
dbms_output.put_line('end loop x: '||x);
end;

-- while
declare
x number;
begin
x:=0;
while x < 10 loop
dbms_output.put_line('x: '||x);
x:=x+1;
end loop;
dbms_output.put_line('end while:x '||x);
end;

-- loop
declare
x number;
begin
x:=0;
loop
x:=x+1;
exit when x>9;
dbms_output.put_line('x: '||x);
end loop;
dbms_output.put_line('end loop x: '||x);
end;

参考:
http://blog.sina.com.cn/s/blog_710faf420100zc6v.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: