zoukankan      html  css  js  c++  java
  • Mysql批量更新

    多个where条件,每个条件对应的更新值不同,需要mysql批量更新

    UPDATE 
       test_table
    SET
        test_target = test_id CASE
        WHEN "123" THEN "456"
        WHEN "789" THEN "101"
        END
    WHERE
        test_id in ['123','789']

    但是在程序中,直接写常量的情况太少,大多数都需要变量遍历

    下面是mybatis的应用:

    UPDATE
         table
    SET
        target = CASE id
    <foreach collection="items" item="item"   close=" END" >
        WHEN #{item.id} THEN #{item.target}
    </foreach>
    WHERE
        apply_id IN
    <foreach collection="items" item="item" open="(" close=")" separator="," >
        #{item.id}
    </foreach>
  • 相关阅读:
    sed
    UCOSIII(二)
    UCOSIII(一)
    IIC
    SPI
    vii
    find
    grep
    Scrum项目4.0
    Scrum项目3.0
  • 原文地址:https://www.cnblogs.com/wanshiming/p/11211453.html
Copyright © 2011-2022 走看看