蔡香满屋
站在牛顿头上吃苹果

为了提高效率,有时候往往不在java程序要中进行遍历处理数据,insert all into 这张方式进行批量插入,但是因为insert all into不能对dblink连接的数据库进行DDL操作,所以需要通过复制表数据进行操作即语法是:insert into table1 select x,y table2

如:

<!-- 初始化学生:两张数据的复制,效率不错 -->
    <insert id="batchInsertStudent" parameterType="com.ly.education.student.api.dto.StudentPayAndRegistrationDto">
		insert into T_XSGL_XSXX_XSJFZC@hxsj(
            XSZCJF_ID,
            XNXQ_ID,
            XS_ID,
            ZCZT,
            CJR,
            CJSJ
        )
        select 
        	A.XSZCJF_ID,
        	A.XNXQ_ID,
        	A.XS_ID,
        	A.ZCZT,
        	A.CJR,
        	A.CJSJ
        FROM (
	           select
	           <!-- 学年学期ID和学号拼接作为学生注册缴费ID即主键 -->
	           (#{semesterId,jdbcType=VARCHAR} || t.XH) as XSZCJF_ID,
	           #{semesterId,jdbcType=VARCHAR} as XNXQ_ID,
	           t.XS_ID as XS_ID,
	           #{studentRegistrationSign,jdbcType=VARCHAR} as ZCZT,
	           #{creator,jdbcType=VARCHAR} as CJR,
	           #{createTime,jdbcType=DATE} as CJSJ
	           from T_XSGL_XSXX_XJXX@hxsj  t
           <where>
           <!-- 因为可以根据不同学生的条件进行多次初始化注册学生信息,防止学生重复添加,需要过滤掉已经在学生缴费注册表中存在的那一批学生 -->
           	    t.XS_ID not in (select XS_ID from T_XSGL_XSXX_XSJFZC@hxsj)
           	 <!-- 根据前端传来的学生筛选条件从学籍表过滤出符合条件的那一批学生 -->
    		<if test="studentTypeCode != null and studentTypeCode != ''">
    			and t.XSLBM = #{studentTypeCode,jdbcType=VARCHAR}
    		</if>
    		<if test="studentStatusStateCode != null and studentStatusStateCode != ''">
    			and t.XSDQZTM = #{studentStatusStateCode,jdbcType=VARCHAR} 
    		</if>
    		<if test="studentInStatusSign != null and studentInStatusSign != ''">
    			and t.SFZJ = #{studentInStatusSign,jdbcType=VARCHAR}
    		</if>
    		<if test="studentAtSchoolSign != null and studentAtSchoolSign != ''">
    			and t.SFZX = #{studentAtSchoolSign,jdbcType=VARCHAR}
    		</if>
    	</where> 
        ) A
    </insert>

  

posted on 2019-03-29 16:04  蔡香满屋  阅读(2082)  评论(0)    收藏  举报