mysql和oracle实现数据更新_oracle和mysql中update联表批量更新数据的区别

之前碰到一个sql语句,在oracle中可以运行,在mysql上就不行,后来查了好久,发现了他们两个联表批量更新数据的区别如下:

(借鉴一下别人的例子)

update :单表的更新不用说了,两者一样,主要说说多表的更新

复制代码 代码如下:

Oracle> Oracle的多表更新要求比较严格,所以有的时候不是很好写,我们可以试试Oracle的游标

update (

select t.charger_id_ new_charger_id_

from t_cus_year_status t

left join t_customer_infos cus on cus.id_ = t.cus_id_

where....

) n set n.new_charger_id_ =6;

复制代码 代码如下:

mysql>

update t_cus_year_status t

left join t_customer_infos cus on cus.id_ = t.cus_id_

set t.charger_id_ =6

where......;

然后仔细观察,可以看出,mysql的更新与oracle不同,是必须要先join on来进行联表,然后才set的,不然就会报语法错误。

附上我写的sql,是一个三表联查

UPDATE bm_crm_archive_info t join (selectDATE(now()) date_check,

t2.oper_per,t2.check_per,t1.pkg_code,t2.app_idfrom bm_crm_apply_rel_info t1 join bm_crm_archive_out_apply t2 on t1.app_id = t2.app_id) y on t.pkg_code =y.pkg_code

join bm_crm_archive_out_apply tt on y.app_id=tt.app_id and y.app_id = '4'

set t.out_per = y.oper_per,t.out_checker = y.check_per,t.out_date=y.date_check,t.status=4,tt.app_status=3

where y.app_id = '4' and y.app_id=tt.app_id

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值