<!-- 批量新增-->
<!-- 注意!!!
mybaits批量插入CLOB字段时不能用下面batchInsertJxCmMaterialsContent2这个sql,会报错报错java.sql.SQLException: ORA-01461: 仅能绑定要插入 LONG 列的 LONG 值
要用batchInsertJxCmMaterialsContent这个sql
有可能问题是出现在当从dual中取数据时,会将clob对象的字段转为Long型
最后的解决方法用到了Begin和end语法:
1.用到begin 和end
2.用到insert into value()语法
不能用insert into select from dual (union all)语法
3.参数,指定 jdbcType=CLOB 类型
-->
<!-- 会出问题的写法 -->
<insert id="batchInsertJxCmMaterialsContent2" parameterType="com.huitu.usif.api.consultation.entities.JxCmMaterialsContent">
insert into ${dbprefix.dbo}JX_CM_MATERIALS_CONTENT (CONTENT_ID, CM_ID, UPDATE_TIME,
CREATE_TIME, CREATE_USER_ID, UPDATE_USER_ID, CM_MATERIALS_CONTENT)
<foreach collection="list" item="item" index="index" separator="union all">
SELECT
#{item.contentId,jdbcType=VARCHAR},
#{item.cmId,jdbcType=VARCHAR},
#{item.updateTime,jdbcType=TIMESTAMP},
#{item.createTime,jdbcType=TIMESTAMP},
#{item.createUserId,jdbcType=VARCHAR},
#{item.updateUserId,jdbcType=VARCHAR},
#{item.cmMaterialsContent,jdbcType=CLOB}
FROM dual
</foreach>
</insert>
<!-- 正确的写法 -->
<insert id="batchInsertJxCmMaterialsContent" parameterType="java.util.List">
begin
<foreach collection="list" item="item" index="index" separator=";">
insert into ${dbprefix.dbo}JX_CM_MATERIALS_CONTENT (CONTENT_ID, CM_ID, UPDATE_TIME,
CREATE_TIME, CREATE_USER_ID, UPDATE_USER_ID, CM_MATERIALS_CONTENT)
values( #{item.contentId,jdbcType=VARCHAR},#{item.cmId,jdbcType=VARCHAR},#{item.updateTime,jdbcType=TIMESTAMP},
#{item.createTime,jdbcType=TIMESTAMP},#{item.createUserId,jdbcType=VARCHAR},#{item.updateUserId,jdbcType=VARCHAR},
#{item.cmMaterialsContent,jdbcType=CLOB})
</foreach>
;end;
</insert>