使用for循环操作DML语句

---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/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值