ORACLE多表關聯UPDATE 語句

來源:互聯網
上載者:User

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)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.