前两个实验是前一段自己做的。后面的实验是一本书上的
实验环境:虚拟机,LINUX+ORACLE 11G
说明:每个实验完成后,需要及时删除表,以便进行下一个实验。 我这里节约篇幅,省略了。
删除重新开始下一个实验
drop table test1 purge;
drop table test2 purge;
truncate table test3;
drop table test3 purge;
alter system flush shared_pool;
方法一:使用布尔积,速度很快。
BYS@ bys001>create table test1 as select rownum a from dual connect by rownum<1001;
BYS@ bys001>alter system flush shared_pool;
BYS@ bys001>create table test3 as select a.* from test1 a,test1 b;
Table created.
Elapsed: 00:00:01.63
BYS@ bys001>select count(*) from test3;
create or replace procedure proc_test1
as
begin
for i in 1 .. 1000000
loop
execute immediate
'insert into test1 values ( '||i||')';
commit;
end loop;
end;
/
Elapsed: 00:13:03.43
BYS@ bys001>select count(*) from test1;
COUNT(*)
----------
1000000
每秒插入一千多条数据,数据条数除所用时间
BYS@ bys001>select 1000000/13/60 from dual;
1000000/13/60
-------------
1282.05128
SQL> select t.sql_text, t.sql_id,t.PARSE_CALLS, t.EXECUTIONS
2 from v$sql t
3 where sql_text like '%insert into test1 %' and rownum <10;
SQL_TEXT SQL_ID PARSE_CALLS EXECUTIONS
------------------------------------------------ ------------- ----------- ----------
insert into test1 values ( 991386) 4d4ywgu81n009 1 1
insert into test1 values ( 997580) 0mg9u6mx6s00j 1 1
insert into test1 values ( 997063) gfkpbx0av000w 1 1
insert into test1 values ( 992660) 3pruwwdb00026 1 1
insert into test1 values ( 997621) 27acn7hja802u 1 1
###########################################################################
方法四:使用绑定变量,一次解析,多次执行
create or replace procedure proc_test1
as
begin
for i in 1 .. 1000000
loop
execute immediate
'insert into test1 values (:aaa)' using i;
commit;
end loop;
10 end;
11 /