Oracle中循环语句用法(for,while,loop)
(2018-02-14 11:21:44)
标签:
for循环用法
while循环用法
loop循环用法
oracle循环语句用法
oracle循环语句实例
|
分类:
Oracle数据库
|
在Oracle的数据处理过程中,我们会用到循环语句来处理某些数据,同时循环语句是我们在使用Oracle数据库时用的最多的语句之一,Oracle中循环语句的写法很多,下面就让我们一起了解下常用循环语句的写法。
一、goto用法
declare x number;
begin
x := 0;
<<repeat_loop>> --循环点
x := x + 1;
dbms_output.put_line(x);
if x < 9
then
--当x的值小于9时,就goto到repeat_loop
goto repeat_loop;
end if;
end;
二、For循环的用法
declare x number; --声明变量
begin x := 1; --给初值
for x in reverse 1 .. 10
loop
--reverse由大到小
dbms_output.put_line('x='||x);
end loop;
dbms_output.put_line('end loop x='||x); --x=1
end;
备注:reverse关键字表示由大到小,去掉该关键字后,默认有小到大。
三、while循环用法
declare
x number;
begin
x := 0;
while x < 9 loop
x := x +
1;
dbms_output.put_line('x='||x);
end loop;
dbms_output.put_line('end loop 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;
本文主要参考资料:https://www.2cto.com/database/201707/656639.html
喜欢
0
赠金笔
加载中,请稍候......