日期:2014-05-16  浏览次数:20433 次

100万条数据,1分钟快速插入(包含过滤,用于按号段增加)
1,创建一张表T_E_PROMOTION2USER
create table T_E_PROMOTION2USER
(
  PROMOTIONID NUMBER(19) not null,
  USERACCOUNT VARCHAR2(256) not null,
  CREATETIME  TIMESTAMP(6) WITH TIME ZONE default SYSDATE not null
);
alter table T_E_PROMOTION2USER
  add constraint PK_T_E_PROMOTION2USER primary key (PROMOTIONID, USERACCOUNT);

2,创建一张表T_E_BATCHINSERT_SEQ
create table T_E_BATCHINSERT_SEQ
(
  SEQ NUMBER(8) not null
);
alter table T_E_BATCHINSERT_SEQ
  add constraint SEQ primary key (SEQ);

3,创建一个存储过程并向表中插入100万条数据
create or replace procedure batchinsert_seq
is
  i        number(38);
begin
   for i in 0 .. 999999 loop
     insert into t_e_batchinsert_seq(seq) values(i);
   end loop;
   commit;
end batchinsert_seq;
/
call batchinsert_seq();

4,再向T_E_PROMOTION2USER这张表插入100万条数据

SQL语句如下:
insert into t_e_promotion2user(promotionid,useraccount,createtime)
           select :promotionid, (:prefix || lpad(:endPhoneNum - seq,:length,'0')),sysdate
           from t_e_batchinsert_seq where seq < :total
           and  (:prefix || lpad(:endPhoneNum - seq,:length,'0'))
           not in (select userAccount from t_e_promotion2user where promotionId = :promotionid)