orcale中,在表中插数据的时候,先判断数据有没有,没有直接插入,如有先把之前数据行置为失效在插入的问题
2017-10-12 16:23
274 查看
思路:先插入一条一模一样的数据置为无效,然后更新为Y的数据
这里insert用到了 insert into select 的方法,这样做的好处是,不用先把要更新的数据查出来在赋值给insert语句,而是在sql中直接可以完成一整条完成记录的插入,即更新了要修改的变量,又能保存其他列中的数据
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中直接可以完成一整条完成记录的插入,即更新了要修改的变量,又能保存其他列中的数据
相关文章推荐
- mysql插入数据时候先检查表中有没有相同的数据如果有就删除原来记录插入,没有就直接插入
- 解决fragment+viewpager第二次进入的时候没有数据的问题
- 解决fragment+viewpager第二次进入的时候没有数据的问题
- js判断input输入框为空时遇到的问题 弹窗后,光标没有定位到输入框,而是直接执行我的处理页面程序
- 插入数据时,保存的date类型时间字段的数据只有年月日,没有时分秒的问题
- springmvc+mybatis+maven项目集成的时候遇到一个问题,项目搭起来以后,http请求怎么都进不到controller中,页面直接返回404错误,控制台没有报任何错误,请大神帮我看看
- orcale 插入大量数据时出的问题
- insert中加入where条件判断,解决插入重复数据的问题
- orcale 插入大量数据时出的问题
- js判断input输入框为空时遇到的问题 弹窗后,光标没有定位到输入框,而是直接执行我的处理页面程序
- 解决fragment+viewpager第二次进入的时候没有数据的问题
- session失效,使用ajax请求数据被拦截,此时正常的处理逻辑是跳到登录界面,而不是界面没有变化(java判断是否是ajax请求)
- Mysql插入数据的时候,中文乱码问题的解决
- oracle 插入数据之前判断是否有记录
- 解决fragment+viewpager第二次进入的时候没有数据的问题
- js判断input输入框为空时遇到的问题 弹窗后,光标没有定位到输入框,而是直接执行我的处理页面程序
- 解决fragment+viewpager第二次进入的时候没有数据的问题
- insert中加入where条件判断,解决插入重复数据的问题
- 怎么解决php调用数据的值或者插入数据库的时候乱码的问题
- springMVC整合hibernate的时候数据插入需要flush问题