---loop循環:
--創建測試表:
suxing@PROD>create table total3(
2 ?t1 number(8),
3 ?t2 number(8),
4 ?cr date default sysdate);
Table created.
#測試表已經創建。
--查看表中原來的數據:
suxing@PROD>select * from total3;
T1 ????????T2 CR
---------- ---------- -------------------
44444 ?????55555 2016-11-12 06:52:08
--使用loop循環往表中插入數據:
suxing@PROD>declare
2 ?v_i int:=1;
3 ?v_sum int:=1;
4 ?begin
5 ?loop
6 ?v_sum:=v_sum + v_i;
7 ?insert into total3(t1,t2) values(v_i,v_sum);
8 ?exit when v_i=10;
9 ?v_i:=v_i + 1;
10 ?end loop;
11 ?end;
12 ?/
PL/SQL procedure successfully completed.
#程序執行完成。
--查看測試表中的數據:
suxing@PROD>select * from total3;
T1 ????????T2 CR
---------- ---------- -------------------
44444 ?????55555 2016-11-12 06:52:08
1 ?????????2 2016-11-12 06:55:27
2 ?????????4 2016-11-12 06:55:27
3 ?????????7 2016-11-12 06:55:27
4 ????????11 2016-11-12 06:55:27
5 ????????16 2016-11-12 06:55:27
6 ????????22 2016-11-12 06:55:27
7 ????????29 2016-11-12 06:55:27
8 ????????37 2016-11-12 06:55:27
9 ????????46 2016-11-12 06:55:27
10 ????????56 2016-11-12 06:55:27
11 rows selected.
前面在while循環中也提到,loop循環與while循環就是執行任務與判斷條件的
先后順序調換了。