欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Mybatis批量插入Oracle数据库

程序员文章站 2022-05-10 19:58:08
...

批量新增时有序列的用法:

	<insert id="insertList" parameterType="java.util.List"  useGeneratedKeys="false">
        INSERT INTO T_JR
            (
            TN_GZZFZBID,
            TN_GZZSZBID,
            TN_LX,
            TC_BM,
            TC_MC
            )
            select SEQ_JR.NEXTVAL,tnGzzszbid,tnLx,tc_dwbm,tc_dwmc
            from(
        <foreach collection="list" item="item" index="index"
            separator="union all">
                select tc_dwbm,tc_dwmc,#{item.tnGzzszbid} as tnGzzszbid,#{item.tnLx} as tnLx
                from t_jcsj_gndws
	 	        where tc_sjdwbm=#{item.tcBm,jdbcType=VARCHAR}
        </foreach>
         )
    </insert>

没有序列时:

	<insert id="insertList" parameterType="java.util.List">
		INSERT ALL
		<foreach collection="list" item="item" index="index"
			separator="">
			INTO T_JR
			( 
			TN_GZZSZBID,
			TN_LX,
			TC_BM,
			TC_MC)
			VALUES
			(
			#{item.tnGzzszbid,jdbcType=DECIMAL},
			#{item.tnLx,jdbcType=DECIMAL},
			#{item.tcBm,jdbcType=VARCHAR},
			#{item.tcMc,jdbcType=VARCHAR}
			)
		</foreach>
		select 1 from dual
	</insert>