Oracle多表关联中的update语句实际应用

以下的文章主要讲述的是 Oracle多表关联中的update语句的实际应用,为了使大家更为仔细的看明白其实际的操作步骤,我们建立了下面的简单模型与构造一部分的测试数据:在某个业务受理子系统BSS中,

客户资料表

 
 
 
  1. create table customers  
  2. (  
  3. customer_id number(8) not null,   

 

客户标示

 
 
 
  1. city_name varchar2(10) not null, 

所在城市

 
 
 
  1. customer_type char(2) not null, 

客户类型

 
 
 
  1. ...  
  2. )  
  3. create unique index PK_customers on customers (customer_id)  

 

由于某些原因,客户所在城市这个信息并不什么准确,但是在

客户服务部的CRM子系统中,通过主动服务获取了部分客户20%的所在

城市等准确信息,于是你将该部分信息提取至一张临时表中:

 
 
 
  1. create table tmp_cust_city  
  2. (  
  3. customer_id number(8) not null,  
  4. citye_name varchar2(10) not null,  
  5. customer_type char(2) not null  
  6. )  

 

1) 最简单的形式

经确认customers表中所有customer_id小于1000均为'北京'

1000以内的均是公司走向全国之前的本城市的老客户:)

 
 
 
  1. update customers 

set city_name='北京'

 
 
 
  1. where customer_id<1000 

2) 两表(多表)关联Oracle update 仅在where字句中的连接

这次提取的数据都是VIP,且包括新增的,所以顺便更新客户类别

 
 
 
  1. update customers a  

使用别名

 
 
 
  1. set customer_type='01'  

01 为vip,00为普通

 
 
 
  1. where exists (select 1  
  2. from tmp_cust_city b  
  3. where b.customer_id=a.customer_id  
  4. )  

 

3) Oracle 两表(多表)关联update 被修改值由另一个表运算而来

 
 
 
  1. update customers a  

使用别名

 
 
 
  1. set city_name=(select b.city_name from tmp_cust_city b where b.customer_id=a.customer_id)  
  2. where exists (select 1  
  3. from tmp_cust_city b  
  4. where b.customer_id=a.customer_id  
  5. )   

 

上述的相关内容就是对 Oracle多表关联的update语句的描述,希望会给你带来一些帮助在此方面。

文章标题:Oracle多表关联中的update语句实际应用
文章起源:http://www.shufengxianlan.com/qtweb/news25/432425.html

网站建设、网络推广公司-创新互联,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联