oracle mybatis 批量插入 自增id
阿新 • • 發佈:2018-12-04
實現方案一:
<!-- 使用sql 實現 --> <insert id="insertBatch" parameterType="java.util.List" useGeneratedKeys="false" > INSERT INTO WF_TASKTEMP_DEALSTAFF (DEAL_ID, TEMP_ID, STAFF_ID,DEAL_TYPE, STATUS) SELECT WF_TASKTEMP_DEALSTAFF$SEQ.NEXTVAL,a.* FROM ( <foreach collection="list" item="item" separator="union all"> SELECT #{item.tempId,jdbcType=VARCHAR}, #{item.staffId,jdbcType=VARCHAR}, #{item.dealType,jdbcType=VARCHAR}, #{item.status,jdbcType=CHAR} FROM dual </foreach> ) a </insert>
實現方案二:
<!-- 使用儲存過程實現 --> <insert id="insertBatch1" parameterType="java.util.List"> begin <foreach collection="list" item="item" index="index"> insert into WF_TASKTEMP_DEALSTAFF ( DEAL_ID, TEMP_ID, STAFF_ID,DEAL_TYPE, STATUS ) values(WF_TASKTEMP_DEALSTAFF$SEQ.nextval, #{item.tempId,jdbcType=VARCHAR}, #{item.staffId,jdbcType=VARCHAR}, #{item.dealType,jdbcType=VARCHAR}, #{item.status,jdbcType=CHAR} ); </foreach> end; </insert>