Oracle中sql有则修改无则添加


例如,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>


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM