update 多表/case when 条件

update A   j set j.replace_job=(select d.replace_job from B  d where j.job_code = d.code and rownum < 2)
where exists (select 1 from wd_schedule_job d where j.job_code = d.code and rownum <2);

update A  j set j.replace_job=nvl((select d.replace_job from B  d where j.job_code = d.code and rownum <2),j.replace_job);

 

 

 

一旦发现条件为真,CASE语句将返回结果,不再进一步下一个评估条件,走成功一个分支,立马返回。
update A  a  set a.effective_route_id = (select case  when b.real_route_id is not null then b.real_route_id
                                                                               when b.adjust_route_id is not null then b.adjust_route_id
                                                                               when b.route_id is not null then b.route_id
                                                                               else effective_route_id end
                                                                               from B  b  where a.id = b.id),
                            a.effective_route_name = (select case when b.real_route_name is not null then b.real_route_name
                                                                               when b.adjust_route_name is not null then b.adjust_route_name
                                                                               when b.route_name is not null then b.route_name
                                                                               else effective_route_name end
                                                                               from B b  where a.id = b.id);

你可能感兴趣的:(oracle,sql)