假定场景:批量导入用户信息
一般批量新增使用 SELECT … INSERT INTO 和 INSERT INTO … SELECT
我们这次使用第二种
一、先建一张用户信息表模拟批量导入用户信息
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 ‘创建时间‘;
二、mybatis xml(传入集合参数,建议批量数量控制在3000以内)
<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>
原文地址:https://www.cnblogs.com/lidada/p/11384540.html
时间: 2024-10-20 23:15:19