当oracle+mybaits批量insert遇到CLOB类型字段

<!--  批量新增-->
  <!--  注意!!!
    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>

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值