分享

Oracle常见几个循环

 IT精彩博文 2012-04-10

1、loop

declare
x number:= 0;
begin
x:=0;

loop
x:=x+1;
/*if x>=10 then
exit;
end if;*/
exit when x>10; -- 此句与上面的if语句作用相同,但这样简练。
DBMS_OUTPUT.PUT_LINE('内 :x='||x);
end loop;

DBMS_OUTPUT.PUT_LINE('外:x='||x);
end;

2、while

declare
x number;
begin
x:=0;

while x<=10 loop
x:=x+1;
DBMS_OUTPUT.PUT_LINE('内:x='||x);
end loop;

DBMS_OUTPUT.PUT_LINE('外:x='||x);
end;


3、for

begin
for x in reverse 1..10 loop -- reverse大到小
DBMS_OUTPUT.PUT_LINE('内:x='||x);
end loop;

DBMS_OUTPUT.PUT_LINE('endget');
end;

4、goto

declare
x number;
begin
x:=0;

<<repeat_loop>>
begin
x:=x+1;
DBMS_OUTPUT.PUT_LINE('内:x='||x);
end;

if x<=10 then
goto repeat_loop;
end if;

DBMS_OUTPUT.PUT_LINE('外:x='||x);
end;

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多