美文网首页
ORACLE 批量新增 和批量更新

ORACLE 批量新增 和批量更新

作者: M_ENG | 来源:发表于2018-11-13 11:08 被阅读0次

    批量新增 parameterType="java.util.List" collection必须为"list"

    <insert id="batchInsert" parameterType="java.util.List">
    
    INSERT INTO HIST_LD_CHANGE(LINE_ID,LINE_NAME)
    
          <foreach collection="list" close=")" open="(" separator="union all" item="item">
    
              SELECT #{item.lineId},#{item.lineName}      FROM DUAL
    
          </foreach>
    </insert>
    

    批量新增 parameterType="java.util.Map" collection为Map中的listKey "lineList"

    <insert id="batchInsert" parameterType="java.util.Map">
    
    INSERT INTO HIST_LD_CHANGE(LINE_ID,LINE_NAME,AREA_ID)
    
          <foreach collection="lineList" close=")" open="(" separator="union all" item="item">
    
              SELECT #{item.lineId},#{item.lineName},#{areaId}  FROM DUAL
    
          </foreach>
    </insert>
    

    批量更新 parameterType="java.util.Map"

    
    <foreach collection="zyldList" open="BEGIN" close="END;" item="item" separator=";" index="index">
    
        UPDATE HIST_LD_CHANGE SET LINE_ID = #{item.lineId},
    
                                  TASK_ID = #{item.taskId},
    
                                  IS_TRANSFER = 1,
    
                                  TRANSFER_USER_ID = #{userId},
    
                                  TRANSFER_TIME = SYSDATE
    
        WHERE LD_FLIGHT_ID = #{item.ldFlightId} AND IS_PERSONAL_DEL = 0
    
        <if test="(zyldList.size-1) == index">
            ;
        </if>
    
    </foreach>
    

    相关文章

      网友评论

          本文标题:ORACLE 批量新增 和批量更新

          本文链接:https://www.haomeiwen.com/subject/dcpkfqtx.html