以下是sql脚本书写:
UPDATE ba_address
SET ship_from_code = CASE
WHEN id = 13845236 THEN 'ISCP13845236' END
WHEN id = 13845237 THEN 'ISCP13845237' END
WHERE ID IN (13845236,13845237 ) AND ADDR_TYPE = 'SHIP'
以下是mybatis XML文件中书写方式:
<update id="updateShipFromCode" parameterType="java.util.List" >
update ba_address
<trim prefix="set" suffixOverrides=",">
<trim prefix="ship_from_code =case" suffix="end,">
<foreach collection="list" item="item" index="index">
<if test="item.id!=null">
when id=#{item.id} then CONCAT('ISCP',#{item.id})
</if>
</foreach>
</trim>
</trim>
<where>
id in
<foreach collection="list" separator="," item="item" open ="(" close=")">
#{item.id}
</foreach>
and addr_type = 'ship'
</where>
</update>