• Mybatis批量插入(oracle)


    有时我们需要批量想数据库中插入数据,如果通过循环一条一条的向数据库中插入,数据量大时容易造成阻塞,不建议使用。其实mybatis自身有很好的实现方式

    1、批量插入

    <insert id="batchInsertCoursePlan" parameterType="java.util.List" >
     <selectKey resultType="Integer" keyProperty="id" order="BEFORE"> 
                 SELECT COURSEARRANGEMENT_SQ.NEXTVAL FROM dual
      </selectKey> 
       INSERT INTO XTEL_CourseArrangement(ID, COURSEID,TIME,CLASSNUMBER)
             SELECT COURSEARRANGEMENT_SQ.NEXTVAL, m.* FROM(
             <foreach collection="list"  index="index" item="coursePlan"  separator="union all">
              select
                 #{coursePlan.courseID} as COURSEID,
                 #{coursePlan.time} as TIME,
                 #{coursePlan.classNumber} as CLASSNUMBER
               from dual
             </foreach>
             )m
    </insert>
    

     2、批量更新

    <update id="updateBatch"  parameterType="java.util.List">
        <foreach collection="list" item="item" index="index" open="begin" close=";end;" separator=";">
            update T_CITY_INDEX t
            set
            t.city_name= #{item.cityName,jdbcType=VARCHAR} ,
            t.district_name= #{item.districtName,jdbcType=VARCHAR} ,
            where t.id = #{item.id,jdbcType=NUMERIC}
        </foreach>
    </update>
    

      

  • 相关阅读:
    test20180922 倾斜的线
    test20180921 量子纠缠
    test20180921 手机信号
    test20180919 选择客栈
    BZOJ3083 遥远的国度
    test20180907 day1
    [ZJOI2010]基站选址
    HDU3584 Cube
    POJ2155 Matrix
    test20180902 day1
  • 原文地址:https://www.cnblogs.com/magic101/p/9507557.html
Copyright © 2020-2023  润新知