MyBatis-批量插入

一、MySql

<!-- 批量插入 -->
  <insert id="batchInsert" parameterType="java.util.List">
      insert into sd_survey_vs_insure
      values  
      <foreach collection="list" item="surveyVsInsure" separator="," index="index">
               (#{surveyVsInsure.id},#{surveyVsInsure.insuranceTypeId},#{surveyVsInsure.surveyId})
      </foreach>
  </insert>

二、Oracle

<!-- 批量添加 -->
<insert id="batchInsert" parameterType="java.util.List">

  INSERT INTO EC_ECUSER_ROLE(ECER_ID,ECER_ECCU_ID,ECER_ECRO_ID)
  SELECT
  SEQ_EC_ECUSER_ROLE.NEXTVAL AS ECERID,ECERECCUID,ECERECROID
  FROM (
    <foreach collection="list" item="ecerItem" separator=" UNION ALL ">
      SELECT #{ecerItem.ecerEccuId} AS ECERECCUID,#{ecerItem.ecerEcroId} AS ECERECROID FROM DUAL
    </foreach>
  )
</insert>

阅读更多
文章标签: SQL 批量插入 MyBatis
个人分类: MyBatis
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭