多表关联的update语句

多表关联的update语句

ID:34754916

大小:69.68 KB

页数:5页

时间:2019-03-10

多表关联的update语句_第1页
多表关联的update语句_第2页
多表关联的update语句_第3页
多表关联的update语句_第4页
多表关联的update语句_第5页
资源描述:

《多表关联的update语句》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库

1、ORACLE UPDATE 语句语法与性能分析的一点看法     选择自 aceplus 的 Blog  关键字   ORACLE UPDATE 语句语法与性能分析的一点看法 出处                  ORACLE UPDATE 语句语法与性能分析的一点看法  为了方便起见,建立了以下简单模型,和构造了部分测试数据:  在某个业务受理子系统BSS中,  --客户资料表  create table customers  (   customer_id   number(8)    not null,  -- 客户标示   city_n

2、ame     varchar2(10) not null,  -- 所在城市   customer_type char(2)      not null,  -- 客户类型    ...  )  create unique index PK_customers on customers (customer_id)  由于某些原因,客户所在城市这个信息并不什么准确,但是在  客户服务部的CRM子系统中,通过主动服务获取了部分客户20%的所在  城市等准确信息,于是你将该部分信息提取至一张临时表中:  create table tmp_cust_c

3、ity  (   customer_id    number(8) not null,   citye_name     varchar2(10) not null,   customer_type  char(2)   not null  )  1) 最简单的形式   --经确认customers表中所有customer_id小于1000均为'北京'   --1000以内的均是公司走向全国之前的本城市的老客户:)   update customers   set    city_name='北京'   where  customer_id<10

4、002) 两表(多表)关联update -- 仅在where字句中的连接   --这次提取的数据都是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      

5、           )3) 两表(多表)关联update -- 被修改值由另一个表运算而来   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_i

6、d=a.customer_id                 )   -- update 超过2个值   update customers a   -- 使用别名   set    (city_name,customer_type)=(select b.city_name,b.customer_type                                      from   tmp_cust_city b                                      where  b.customer_id=a.cu

7、stomer_id)   where  exists (select 1                   from   tmp_cust_city b                  where  b.customer_id=a.customer_id                 )   注意在这个语句中,                                   =(select b.city_name,b.customer_type                                      from   t

8、mp_cust_city b                                      where  b.custome

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。