假定場景:批量導入用戶信息java
通常批量新增使用 SELECT … INSERT INTO 和 INSERT INTO … SELECTmybatis
咱們此次使用第二種app
1、先建一張用戶信息表模擬批量導入用戶信息less
create table u_info{ id NUMBER not null, info_no VARCHAR2(32) not null, name VARCHAR2(32) not null, birthday DATE, age NUMBER, create_date DATE not null } -- 自動按天數分區 -- tablespace TBS_DATA --partition by range (create_date) interval (numtodsinterval(1, 'DAY')) --(partition P20190101 values less than (TO_DATE('2019-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))) ; --create unique index IU_INFO_NO_DATE on u_info (info_no,create_date) tablespace TBS_IDX online local; -- Add comments comment on table u_info is '用戶信息表'; comment on column u_info.id is '主鍵'; comment on column u_info.info_no is '用戶編號'; comment on column u_info.name is '姓名'; comment on column u_info.birthday is '生日'; comment on column u_info.age is '年齡'; comment on column u_info.create_date is '建立時間';
2、mybatis xml(傳入集合參數,建議批量數量控制在3000之內)spa
<insert id="insertBatch" parameterType="java.util.List"> /**UserInfoMapper.insertBatch*/ INSERT INTO u_info( id, info_no, name, birthday, age, create_date ) SELECT S.*, SYSDATE FROM( <foreach item="bean" index="index" collection="list" separator="UNION ALL"> SELECT #{bean.id, jdbcType=DECIMAL}, #{bean.infoNo, jdbcType=VARCHAR}, #{bean.name, jdbcType=VARCHAR}, #{bean.birthday, jdbcType=TIMESTAMP}, #{bean.age, jdbcType=DECIMAL} FROM DUAL </foreach> ) S </insert>