update 子查询隐含风险

update examinees s
set (s.birthdate,
s.issuecertdate,
s.acceptgradedate,
s.lastmodifieddate) =
(select to_char(t.birthdate, ‘yyyy/mm/dd’),
to_char(t.issuecertdate, ‘yyyy/mm/dd’),
to_char(t.acceptgradedate, ‘yyyy/mm/dd’),
to_char(t.lastmodifieddate, ‘yyyy/mm/dd’) from examinees_impto_zt t where
s.examineeid = to_char(t.examineeid))
where exists(select 1 from examinees_impto_zt b where s.examineeid = to_char(b.examineeid));

一定加入 where exists ..条件,防止将子查询不存在的记录更新成null

猜你喜欢

转载自libaxiaoyuan.iteye.com/blog/2233590