Mybatis 批量插入帶oracle序列 例子
<insert id="inserts" parameterType="java.util.List">
insert into PRESON
select SEQ_PRESON_ID.NEXTVAL,A.* from(
<foreach collection="list" item="item" index="index"
separator="UNION">
SELECT
#{item.presonName},
#{item.presonTel},
#{item.presonEmail},
#{item.presonAge}
from dual
</foreach>
) A
</insert>
<!--
批量插入 UNION ALL-->
<insert id="inserts" parameterType="java.util.List">
insert into PRESON
select SEQ_PRESON_ID.NEXTVAL,A.* from(
<foreach collection="list" item="item" index="index"
separator="UNION
ALL">
SELECT
#{item.presonName},
#{item.presonTel},
#{item.presonEmail},
#{item.presonAge}
from dual
</foreach>
) A
</insert>
例子:
select 'order' from dual union all select 'order' from dual; --不會去重
select 'order' from dual union select 'order' from dual; --會去重
批量插入(不支援序列的方式)
insert into order_payment_wx_log
(PAYMENT_LOG_ID, BUSINESS_TYPE)
(select 111, 'order' from dual union all select 222, 'order' from dual);