orcale如下:(这里要注意的是:useGeneratedKeys="false" )
方式1:oracle批量插入使用
insert all
into table(...) values(...) i
nto table(...) values(...)
select 1 from dual;
<insert id="insertListBatch" parameterType="java.util.List" useGeneratedKeys="false">
INSERT ALL
<foreach item="item" index="index" collection="list">
INTO student
(
ID,
name,
age,
sex,
CREATE_TIME
) VALUES
(
#{item.id, jdbcType=NUMERIC},
#{item.name, jdbcType=VARCHAR},
#{item.age, jdbcType=VARCHAR},
#{item.sex, jdbcType=VARCHAR},
#{item.createdTime, jdbcType=NUMERIC}
)
</foreach>
</insert>
@Insert("<script>" +
"INSERT ALL "+
"<foreach collection='list' item='kLine' index='index'>" +
"INTO T_CFG_BENEFIT_TEMP (BENEFIT_TYPE) " +
"VALUES " +
"(#{kLine.benefitType,jdbcType=VARCHAR}," +
")" +
"</foreach>" +
"SELECT FROM DUAL "+
"</script>")
方式2: insert into table(...) (select ... from dual) union all (select ... from dual)
<insert id="insertListBatch" parameterType="java.util.List" useGeneratedKeys="false">
INSERT INTO T_APPLAUD
(
ID,
name,
age,
sex,
CREATE_TIME
)
<foreach item="item" index="index" collection="list" separator="union all">
(
SELECT
#{item.id},
#{item.name},
#{item.age},
#{item.sex},
#{item.createdTime}
FROM DUAL
)
</foreach>
</insert>
@Insert("<script>" +
"insert into T_CFG_BENEFIT_TEMP (BENEFIT_TYPE ) " +
"<foreach collection='list' item='kLine' index='index' separator='union all'>" +
"(SELECT " +
"#{kLine.benefitType,jdbcType=VARCHAR}"
"FROM DUAL)" +
"</foreach>" +
"</script>")