Oracle多表關(guān)聯(lián)中的update語(yǔ)句實(shí)際應(yīng)用
以下的文章主要講述的是 Oracle多表關(guān)聯(lián)中的update語(yǔ)句的實(shí)際應(yīng)用,為了使大家更為仔細(xì)的看明白其實(shí)際的操作步驟,我們建立了下面的簡(jiǎn)單模型與構(gòu)造一部分的測(cè)試數(shù)據(jù):在某個(gè)業(yè)務(wù)受理子系統(tǒng)BSS中,
客戶資料表
- create table customers
- (
- customer_id number(8) not null,
客戶標(biāo)示
- city_name varchar2(10) not null,
所在城市
- customer_type char(2) not null,
客戶類型
- ...
- )
- create unique index PK_customers on customers (customer_id)
由于某些原因,客戶所在城市這個(gè)信息并不什么準(zhǔn)確,但是在
客戶服務(wù)部的CRM子系統(tǒng)中,通過(guò)主動(dòng)服務(wù)獲取了部分客戶20%的所在
城市等準(zhǔn)確信息,于是你將該部分信息提取至一張臨時(shí)表中:
- create table tmp_cust_city
- (
- customer_id number(8) not null,
- citye_name varchar2(10) not null,
- customer_type char(2) not null
- )
1) 最簡(jiǎn)單的形式
經(jīng)確認(rèn)customers表中所有customer_id小于1000均為'北京'
1000以內(nèi)的均是公司走向全國(guó)之前的本城市的老客戶:)
- update customers
set city_name='北京'
- where customer_id<1000
2) 兩表(多表)關(guān)聯(lián)Oracle update 僅在where字句中的連接
這次提取的數(shù)據(jù)都是VIP,且包括新增的,所以順便更新客戶類別
- update customers a
使用別名
- set customer_type='01'
01 為vip,00為普通
- where exists (select 1
- from tmp_cust_city b
- where b.customer_id=a.customer_id
- )
3) Oracle 兩表(多表)關(guān)聯(lián)update 被修改值由另一個(gè)表運(yùn)算而來(lái)
- 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 1
- from tmp_cust_city b
- where b.customer_id=a.customer_id
- )
上述的相關(guān)內(nèi)容就是對(duì) Oracle多表關(guān)聯(lián)的update語(yǔ)句的描述,希望會(huì)給你帶來(lái)一些幫助在此方面。
【編輯推薦】