oracle中的循环简析
一、LOOP 循环是最简单的循环,也是无限循环,只能用 EXIT 终止。
Sql代码
declare
starts number:=1;
counts number:=20;
begin
loop
dbms_output.put_line(starts);
starts:=starts+1; www.2cto.com
exit when starts>=counts;
end loop;
end;
--输出1-19
二、WHILE 循环,判断条件,成立接着走循环体。
Sql代码
declare
starts number:=1;
counts number:=20;
begin www.2cto.com
while starts
dbms_output.put_line(starts);
starts:=starts+1;
end loop;
end;
--同样输出1-19
三、FOR 循环,确定循环次数,并指定下限和上限,然后递增或递减,默认递增,若加 REVERSE 关键字,则递减。
Sql代码
declare
starts number:=1;
counts number:=20;
begin
for i in starts..counts loop
dbms_output.put_line(i);
end loop;
end;
--输出1-20
www.2cto.com
declare
starts number:=1;
counts number:=20;
begin
for i in REVERSE starts..counts loop
dbms_output.put_line(i);
end loop;
end;
--输出20-1
摘自 Ear's blog
oracle中的循环简析 - ORA-00020,ORA-01304,ORA-27101基础故障处理 Nov 02, 2016
- dbms_metadata遇到ORA-31603的解决方案 Aug 23, 2017
- ORA-00600([ksires_1])错误的解决方案 Aug 03, 2016
- Oracle数据字典之all_视图 Jan 02, 2017
- oracle添加列到指定位置的方法 Aug 14, 2016
- Oracle归档日志(ARCH/ARCn)进程简介 Feb 21, 2017
oracle行列转换函数的使用 Oct 28, 2016
- ORA-12519,TNS:no appropriate service handler found的问题 Feb 20, 2017