我们都知道,在Oracle数据库中,对单表进行更新采用标准update语法效率是非常高的,语法为UPDATE 表名称 SET 列名称 = 新值 WHERE 列名称 = 某值,如下SQL所示:
update t_join_situation set join_state = '1' where year='2011'
如果涉及关联表,并把一个表的字段值更新到另一个表中的字段去,采用以上更新方式,语句通常这样写:update 表a set a.字段1 = (select b.字段1 from 表b where a.字段2=b.字段2) where exists(select 1 from 表b where a.字段2=b.字段2),如下SQL所示:
update t_join_situation a set a.join_state=(select b.join_state from t_people_info b
where a.people_number=b.people_number
and a.year='2011' and a.city_number='M00000' and a.town_number='M51000')
where exists (select 1 from t_people_info b
where a.people_number=b.people_number
and a.year='2011' and a.city_number='M00000' and a.town_number='M51000')
但是,这样更新的效率是非常低的。
这里,推荐几种多表关联update优化的方式:
(1)inline view 更新法
inline view更新法就是更新一个临时建立的视图。如:update (sele