insertOrUpdateBatch样例代码

insertOrUpdateBatch需要注意的点

<insert id="insertOrUpdateFutureLimitPositionValueBatch">
        merge into tusr_futurelimitpositionvalue a
        USING
        (
        <foreach collection="list" item="item" separator="union all">
            (select
            #{item.futureLimitPositionId} as future_limit_position_id,
            #{item.limitPositionPointId} as limit_position_point_id,
            #{item.compareDir,jdbcType=CHAR} as compare_dir,
            #{item.positionQty,jdbcType=DECIMAL} as position_qty,
            #{item.thresholdType,jdbcType=CHAR} as threshold_type,
            #{item.thresholdValue,jdbcType=DECIMAL} as threshold_value
            from dual
            )
        </foreach>
        ) t
        ON (a.future_limit_position_id = t.future_limit_position_id and a.limit_position_point_id = t.limit_position_point_id)
        WHEN MATCHED THEN
        UPDATE
        <set>
            a.compare_dir = t.compare_dir,
            a.position_qty = t.position_qty,
            a.threshold_type = t.threshold_type,
            a.threshold_value = t.threshold_value
        </set>
        WHEN NOT MATCHED THEN
        insert
        (
        a.future_limit_position_id,
        a.limit_position_point_id,
        a.compare_dir,
        a.position_qty,
        a.threshold_type,
        a.threshold_value
        )
        VALUES
        (
        t.future_limit_position_id,
        t.limit_position_point_id,
        t.compare_dir,
        t.position_qty,
        t.threshold_type,
        t.threshold_value
        )
    </insert>
  1. 注意最后一个字段不能有多余的逗号,否则会报无效字段问题
  2. 在merge时所比较的on的字段不能与update语句中的字段重复,否则会报
Error occurred during SQL query execution

原因:
 SQL 错误 [38104] [99999]: ORA-38104: 无法更新 ON 子句中引用的列: "A"."FUTURE_LIMIT_POSITION_ID"

错误案例:

merge into tusr_futurelimitpositionvalue a
        USING
        (
        <foreach collection="list" item="item" separator="union all">
            (select
            #{item.futureLimitPositionId} as future_limit_position_id,
            #{item.limitPositionPointId} as limit_position_point_id,
            #{item.compareDir,jdbcType=CHAR} as compare_dir,
            #{item.positionQty,jdbcType=DECIMAL} as position_qty,
            #{item.thresholdType,jdbcType=CHAR} as threshold_type,
            #{item.thresholdValue,jdbcType=DECIMAL} as threshold_value
            from dual
            )
        </foreach>
        ) t
        ON (a.future_limit_position_id = t.future_limit_position_id and a.limit_position_point_id = t.limit_position_point_id)
        WHEN MATCHED THEN
        UPDATE
        <set>
            a.compare_dir = t.compare_dir,
            a.position_qty = t.position_qty,
            a.threshold_type = t.threshold_type,
            a.threshold_value = t.threshold_value
        </set>
        WHEN NOT MATCHED THEN
        insert
        (
        a.future_limit_position_id,
        a.limit_position_point_id,
        a.compare_dir,
        a.position_qty,
        a.threshold_type,
        a.threshold_value
        )
        VALUES
        (
        t.future_limit_position_id,
        t.limit_position_point_id,
        t.compare_dir,
        t.position_qty,
        t.threshold_type,
        t.threshold_value
        )
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值