例如,demo表中有name,price,nowtime等字段,需要根据name字段进行判断,存在则修改,不存在则添加
<update id="updateshoppings" parameterType="String">
MERGE INTO demo t1
USING(SELECT #{name} name,#{price} price,#{nowtime} nowtime FROM dual) t2
ON(t1.name=t2.name)
WHEN MATCHED THEN
update set t1.price=t2.price,t1.nowtime=t2.nowtime
WHEN NOT MATCHED THEN
insert(name,price,nowtime) VALUES(t2.name,t2.price,t2.nowtime)
</update>