先上代码:
<insert id="copyinsertBatch" parameterType="java.util.List" useGeneratedKeys="false" >
begin
insert into CEB_DEPARTURE_HEAD_HIS
<foreach item="item" collection="dataList" separator=" UNION ALL " index="index" >
<if test="index != 0">
<choose>
<when test="index % 1000 ==999">; insert into CEB_DEPARTURE_HEAD_HIS </when>
</choose>
</if>
select * from CEB_DEPARTURE_HEAD where ID = #{item}
</foreach>;
insert into CEB_DEPARTURE_LIST_HIS
<foreach item="item" collection="dataList" separator=" UNION ALL " index="index" >
<if test="index != 0">
<choose>
<when test="index % 1000 ==999">; insert into CEB_DEPARTURE_LIST_HIS </when>
</choose>
</if>
select * from CEB_DEPARTURE_LIST where ID = #{item}
</foreach>;
end;
</insert>
重点:必须用 begin end; 把多条sql语句 拼再一起,每个sql 用分号“;”隔开;
begin
sql1;
sql2;
end;
弊端:没有返回执行量
24k唇动 发布了2 篇原创文章 · 获赞 0 · 访问量 426 私信 关注