MyBatis Merge into batch usage issues

Source: Internet
Author: User
All data in insert and update needs to be obtained from the using, so that the batch merge into effect is achieved
MERGE into Tm_user_cart_info T1
USING
(
<foreach collection= "List" item= "item" index= "index" separator= "union" >
SELECT
Case when TEMP1. F_CART_ID is NULL and then TEMP. f_cart_id ELSE TEMP1. f_cart_id END f_cart_id,
TEMP. F_goods_num,
TEMP. F_USER_ID,
TEMP. F_region_num,
TEMP. F_channel_num,
TEMP. F_goods_count
From
(SELECT #{cartid} f_cart_id,#{goodsnum} F_goods_num,#{userid} F_user_id,#{regionnum} F_region_num,#{channelnum} F_ Channel_num,#{goodscount} F_goods_count from DUAL) TEMP
Left JOIN
(
SELECT * from Tm_user_cart_info T2
WHERE 1=1 and T2. f_user_id = #{userid}
and T2. F_goods_num = #{goodsnum}
and T2. F_region_num = #{regionnum}
and T2. F_channel_num = #{channelnum}
And not EXISTS (SELECT "from Tm_user_cart_market T3 WHERE T3. f_cart_id = T2. F_CART_ID)
) TEMP1 on TEMP1. F_goods_num = TEMP. F_goods_num
</foreach>
) T
On (T1. f_cart_id = t.f_cart_id)
When matched then
UPDATE SET T1. F_goods_count = T1. F_goods_count + T.f_goods_count, T1. F_update_time = (SELECT to_char (sysdate, ' Yyyymmddhh24miss ') from DUAL)
When isn't matched then
INSERT
(f_cart_id, F_channel_num, F_merchant_num, f_user_id, F_goods_num, F_goods_count, F_add_time, F_REGION_NUM)
VALUES
(t.f_cart_id, T.f_channel_num, ", t.f_user_id, T.f_goods_num, T.f_goods_count,

(SELECT to_char (sysdate, ' Yyyymmddhh24miss ') from DUAL), T.f_region_num)



#{xxxx} changed to #{item.xxxx}



Reprinted from: http://bbs.csdn.net/topics/390940098

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.