為了方便起見
在某個業務受理子系統BSS中
create table customers
(
customer_id number(
city_name varchar
customer_type char(
)
create unique index PK_customers on customers (customer_id)
由於某些原因
客戶服務部的CRM子系統中
城市等准確信息
create table tmp_cust_city
(
customer_id number(
citye_name varchar
customer_type char(
)
update customers
set city_name=
where customer_id<
update customers a
set customer_type=
where exists (select
from tmp_cust_city b
where b
)
update customers a
set city_name=(select b
where exists (select
from tmp_cust_city b
where b
)
update customers a
set (city_name
from tmp_cust_city b
where b
where exists (select
from tmp_cust_city b
where b
)
注意在這個語句中
=(select b
from tmp_cust_city b
where b
)
與
(select
from tmp_cust_city b
where b
)
是兩個獨立的子查詢
如果捨棄where條件
更新
有可能不能提供
所以報錯(如果指定的列
// *Cause:
// *Action:
一個替代的方法可以采用
update customers a
set city_name=nvl((select b
或者
set city_name=nvl((select b
考慮A表使用INDEX的情況
set serveroutput on
declare
cursor city_cur is
select customer_id
from tmp_cust_city
order by customer_id;
begin
for my_cur in city_cur loop
update customers
set city_name=my_cur
where customer_id=my_cur
/** 此處也可以單條/分批次提交
end loop;
end;
在oracle的update語句語法中
update (select a
from customers a
tmp_cust_city b
where b
)
set city_name=new_name
這樣能避免對B表或其索引的
或primary key
// *Cause: An attempt was made to insert or update columns of a join view which
// map to a non
// *Action: Modify the underlying base tables directly
回到
update customers a
set city_name=(select b
where exists (select
from tmp_cust_city b
where b
)
當對於一個給定的a
(select b
返回多余
// *Cause:
// *Action:
一個比較簡單近似於不負責任的做法是
update customers a
set city_name=(select b
如何理解
仍已上述例子來描述
having 字句查看重復的紀錄
(select b
from tmp_cust_city b
where b
group by b
having count(*)>=
)
From:http://tw.wingwit.com/Article/program/Oracle/201311/18909.html