FOR循环重复的控制结构,可以有效地编写需要执行的特定次数的循环。操作语法如下:

FOR counter IN [reverse] initial_value .. final_value LOOP
sequence_of_statements;
END LOOP;

操作实例源码:

-- Created on 2018/3/23 by E.WANG 
/*
语法:
FOR counter IN [reverse] initial_value .. final_value LOOP
sequence_of_statements;
END LOOP;
*/
declare
--保存求和结果
sum_result integer:=0;
begin
--求从1到1000的累加和
for var in 1..1000 loop
sum_result:=sum_result+var;
end loop;
dbms_output.put_line('The result of 1..1000 is : ' || sum_result);

--使用REVERSE关键翻转顺序
for var in reverse 1..10 loop
dbms_output.put_line('The '||var || ' loop');
end loop;

end;

窗口截屏:

PL/SQL FOR循环语句操作实例_oracle

运行结果截图:

PL/SQL FOR循环语句操作实例_oracle_02