mybatis oracle資料庫批次插入資料,忽略主鍵重複

Desperado!發表於2024-03-14

dao方法

Integer insertPackagesNew(@Param("list") List<InfCollectpackage> list);

mapper.xml

    <insert id="insertPackagesNew" parameterType="java.util.List">
        MERGE INTO INF_COLLECTPACKAGE A
        USING (<foreach collection="list" item="item" index="index" separator="union">
            SELECT #{item.idempotent} idempotent, #{item.waveno} waveno, #{item.workstation} workstation, #{item.binno} binno
        ,#{item.shopid} shopid, #{item.shopname} shopname, #{item.packageno,} packageno, #{item.sku} sku
        ,#{item.batchno} batchno, #{item.barcode} barcode, #{item.goodsname} goodsname, #{item.qty} qty
        ,#{item.collectpackagetime} collectpackagetime, #{item.zt} zt, #{item.qty_num} qty_num, #{item.xiactime} xiactime
        from dual
        </foreach>) B
        ON (A.idempotent = b.idempotent)
        WHEN NOT MATCHED THEN
        INSERT
        (IDEMPOTENT,WAVENO,WORKSTATION,BINNO,SHOPID,
        SHOPNAME,PACKAGENO,SKU,BATCHNO,BARCODE,
        GOODSNAME,QTY,COLLECTPACKAGETIME,ZT,
        QTY_NUM,XIACTIME)
        VALUES
        (B.IDEMPOTENT, B.WAVENO, B.WORKSTATION, B.BINNO, B.SHOPID,
         B.SHOPNAME, B.PACKAGENO, B.SKU, B.BATCHNO, B.BARCODE,
         B.GOODSNAME, B.QTY, B.COLLECTPACKAGETIME, B.ZT,
         B.QTY_NUM, B.XIACTIME)
    </insert>

相關文章