ITeye博客

【SQL】oracle中的多表更新

duduli · 2019-07-03 14:41 · oracle · 数据库 · Markdown

对于多表更新标准的sql存在这样的方法

update t_store_i a,t_accept_d b set a.purtax=b.purtax,a.saletax=b.saletax where a.wareid=b.wareid and a.batid=b.batid and a.compid=7 and a.purtax<>b.purtax and a.saletax<>b.saletax 

或者

update t_store_i a 
set a.purtax=b.purtax,a.saletax=b.saletax 
where exists (select 1
from t_accept_d b
where a.wareid=b.wareid and a.batid=b.batid and a.compid=7 and a.purtax<>b.purtax and a.saletax<>b.saletax
)

但是对于oracle来说需要采用merge into的方式才能更新。


merge into d_20190127 a
using d_20190128 b
on (a.billno = b.billno)
--when matched then update set a.sap_note=b.sap_note    -- 可不执行
when not matched then insert(a.billno,a.transtime,a.sap_status,a.sap_note,a.sap_result) values(b.billno,b.transtime,b.sap_status,b.sap_note,b.sap_result) 

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。