ORACLE多表關聯UPDATE 語句
1) 最簡單的形式 SQL 代碼
--經確認customers表中所有customer_id小於1000均為'北京'
--1000以內的均是公司走向全國之前的本城市的老客戶:)update customersset city_name='北京'where customer_id<1000
2) 兩表(多表)關聯update -- 僅在where字句中的串連 SQL 代碼
--這次提取的資料都是VIP,且包括新增的,所以順便更新客戶類別update customers a -- 使用別名set customer_type='01' --01 為vip,00為普通where exists (select 1from tmp_cust_city bwhere b.customer_id=a.customer_id)
3) 兩表(多表)關聯update -- 被修改值由另一個表運算而來 SQL 代碼
update customers a -- 使用別名set city_name=(select b.city_name from tmp_cust_city b where b.customer_id=a.customer_id)where exists (select 1from tmp_cust_city bwhere b.customer_id=a.customer_id)-- update 超過2個值update customers a -- 使用別名set (city_name,customer_type)=(select b.city_name,b.customer_typefrom tmp_cust_city bwhere b.customer_id=a.customer_id)where exists (select 1from tmp_cust_city bwhere b.customer_id=a.customer_id)