简体   繁体   English

如何从Oracle的SQL中的其他表更新

[英]How to update from other table in Oracle's sql

I have two table and I want update table A from Table B in Oracle's sql 我有两个表,我想从Oracle sql中的表B更新表A

table A
customer_id    geo_id     geo
1234567890       3521     texas
0987654321       3624     dallas
1597536842       3121     mexicocity
table B
geo_id        customer_id
8745          1234567890
2145          0987654321
3699          1597536842
update table A
set   geo_id   = (select geo_id from table B)
where tableA.customer_id = tableB.customer_id;

Use MERGE statement 使用MERGE语句

MERGE INTO tablea a 
     using tableb b ON( a.customer_id = b.customer_id ) 
WHEN matched THEN 
  UPDATE SET a.geo_id = b.geo_id 

OR a Correlated update 或相关更新

update tablea a set 
    a.geo_id = (select geo_id from 
                      tableb b 
                      where a.customer_id = b.customer_id)

DEMO 演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM