Oracle多表关联如何更新多个字段

时间:2022-04-03 13:02:31

注意点:
1、被update主表一定要加上过滤条件。
2、查询出来更新结果集,同时也要作为被更新主表的条件,作为同步大家都是更新这部分数据。
update student stu
  set (stu.name,stu.sex) =
  (select bak.name,bak.sex
  from student_bak bak
  where bak.id = stu.id
  and stu.age = 20
  )
  where exists (select 1
  from student_bak bak
  where bak.id = stu.id
  and stu.age = 20
  )