SQL> desc test
名称 是否为空? 类型
----------------------------------------- -------- ------------
X NUMBER
Y CHAR(100)
向test表插入50000行数据,第一次用普通的for循环
SQL> declare
2 type numlist is table of number;
3 type charlist is table of varchar(90);
4 n numlist := numlist();
5 c charlist := charlist();
6 begin
7 for i in 1 .. 50000 loop
8 n.extend;
9 c.extend;
10 n(i) := i;
11 c(i) := ''||i;
12 end loop;
13 for i in 1 .. 50000 loop
14 insert into test values (n(i), c(i));
15 end loop;
16 end;
17 /
PL/SQL 过程已成功完成。
已用时间: 00: 00: 03.55
SQL> truncate table test;
表被截断。
已用时间: 00: 00: 00.25
SQL> alter system flush shared_pool;
系统已更改。
已用时间: 00: 00: 00.01
第二次用批量绑定forall关键字
SQL> declare
2 type numlist is table of number;
3 type charlist is table of varchar(90);
4 n numlist := numlist();
5 c charlist := charlist();
6 begin
7 for i in 1 .. 50000 loop
8 n.extend;
9 c.extend;
10 n(i) := i;
11 c(i) := ''||i;
12 end loop;
13 forall i in 1 .. 50000
14 insert into test values (n(i), c(i));
15 end;
16 /
PL/SQL 过程已成功完成。
已用时间: 00: 00: 00.54
可以看出时间上的差距非常明显
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/25361369/viewspace-709741/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/25361369/viewspace-709741/