您的位置:首页 > 其它

orcale中,在表中插数据的时候,先判断数据有没有,没有直接插入,如有先把之前数据行置为失效在插入的问题

2017-10-12 16:23 274 查看
思路:先插入一条一模一样的数据置为无效,然后更新为Y的数据

flatManageDao.insertFloatPriceBatch(modelId, price);
flatManageDao.updateFloatPriceBatch(modelId, price);

<insert id="insertFloatPriceBatch">
insert into tb_mall_fix_thick
(model_id, fix_id, thick, refer_thick_min, refer_thick_max, fix_price, float_price, create_date, is_valid, sort, notes)
select
model_id, sys_guid(), thick, refer_thick_min, refer_thick_max, fix_price, float_price, create_date, 'N', sort, notes
from TB_MALL_FIX_THICK where model_id = #{modelId} and is_valid = 'Y'
</insert>

<update id="updateFloatPrice">
update TB_MALL_FIX_THICK t set t.float_price = #{price},t.create_date = sysdate where t.fix_id= #{fixId} and t.is_valid = 'Y'
</update>


这里insert用到了 insert into select 的方法,这样做的好处是,不用先把要更新的数据查出来在赋值给insert语句,而是在sql中直接可以完成一整条完成记录的插入,即更新了要修改的变量,又能保存其他列中的数据
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐