oracle-update
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
)
-- 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.customer_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 tmp_cust_city b
where b.customer_id=a.customer_id
)
与
(select 1
from tmp_cust_city b
where b.customer_id=a.customer_id
)
是两个独立的子查询,查看执行计划可知,对b表/索引扫描了2篇;
如果舍弃where条件,则默认对A表进行全表
更新,但由于(select b.city_name from tmp_cust_city b where where
b.customer_id=a.customer_id)
有可能不能提供"足够多"值,因为tmp_cust_city只是一部分客户的信息,
所以报错(如果指定的列--city_name可以为NULL则另当别论):
01407, 00000, "cannot update (%s) to NULL"
// *Cause:
// *Action:
一个替代的方法可以采用:
update customers a -- 使用别名
set city_name=nvl((select b.city_name from tmp_cust_city b where
b.customer_id=a.customer_id),a.city_name)
或者
set city_name=nvl((select b.city_name from tmp_cust_city b where
b.customer_id=a.customer_id),'未知')
-- 当然这不符合业务逻辑了
Oracle -Update 多表关联_IT/计算机_专业资料。一条 Update 更新语句是不能更新多张表的,除非使用触发器隐含更新。而表的 更新操作中,在很多情况下需要在表达式...
Oracle-更新-OPatch-工具版本-的方法-说明_计算机软件及应用_IT/计算机_专业资料。Oracle-教程Oracle 更新 OPatch 工具版本 的方法 说明Oracle 更新 OPatch 工具...
5) 关联 update 的一个特例以及性能再探讨 在 oracle 的 update 语句语法中,除了可以 update 表之外,也可以是视图, 所以有以下 1 个特例: update (select a...
oracle的update语句研究_IT/计算机_专业资料。Oracle 的 update 语句优化研究一、 update 语句的语法与原理 1. 语法单表:UPDATE 表名称 SET 列名称 = 新值 ...
oracle update语句的几点写法_计算机软件及应用_IT/计算机_专业资料。oracle update语句的几点写法 update两表关联的写法包括字查询 update t2 set parentid=(...
Oracle_Oracle之UPDATE 关键字NOWAIT的详解_IT/计算机_专业资料。Oracle 数据库Oracle 之 UPDATE 关键字 NOWAIT 的详解 1、FOR UPDATE 和 FOR UPDATE NOWAIT 的...
oracle_update_计算机软件及应用_IT/计算机_专业资料。oracle_update about psu & psrLinux(RHEL5)下 Oracle 10g 版本升级(10.2.0.1.0-10.2.0.5.0) (...
oracle更新语法_计算机软件及应用_IT/计算机_专业资料。: 1.一般语法 update tab set col = ... [where ...] =后可以有子查询,但是必须对于tab的每一列返...
5) 关联 update 的一个特例以及性能再探讨 在 oracle 的 update 语句语法中,除了可以 update 表之外,也可以是视图,所以有以下 1 个特例: update (select a....
5) 关联update的一个特例及性能再探讨 在oracle的update语句语法中,除了能update表之外,也能是视图,所以有以下1个特例: update (select a.city_name,b.city_...
热门文档