---for循环:
--创建测试表:
suxing@PROD>create table total2(
2 t1 number(8),
3 t2 number(8),
4 cr date default sysdate);
Table created.
#测试表创建完成。
suxing@PROD>insert into total2(t1,t2) values(2222,3333);
1 row created.
--查看表中原有的数据:
suxing@PROD>select * from total2;
T1 T2 CR
---------- ---------- ---------
2222 3333
2222 3333 12-NOV-16
--使用for循环往表中插入数据:
suxing@PROD>declare
2 v_i int:=1;
3 v_factorial int:=1;
4 begin
5 for v_i in 1..10 loop
6 v_factorial :=v_factorial*v_i;
7 insert into total2(t1,t2) values(v_i,v_factorial);
8 end loop;
9 end;
10 /
PL/SQL procedure successfully completed.
#程序执行完成。
--查看表中的数据:
suxing@PROD>select * from total2;
T1 T2 CR
---------- ---------- -------------------
2222 3333 2016-11-12 06:38:56
1 1 2016-11-12 06:44:14
2 2 2016-11-12 06:44:14
3 6 2016-11-12 06:44:14
4 24 2016-11-12 06:44:14
5 120 2016-11-12 06:44:14
6 720 2016-11-12 06:44:14
7 5040 2016-11-12 06:44:14
8 40320 2016-11-12 06:44:14
9 362880 2016-11-12 06:44:14
10 3628800 2016-11-12 06:44:14
for循环是基于给定的范围内循环,当超出范围内,自动跳出循环,它与while和loop两种循环体有所区别。
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/31392094/viewspace-2128349/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/31392094/viewspace-2128349/