1. 通过更新VIEW的方式

      1. update
      2. (select emp.dname, dept.dname as new_dname
      3. from emp
      4. inner join dept on dept.deptno = emp.deptno)
      5. set dname = new_name

      执行时,可能会出现“无法修改与非键值保存表对应的列”,这时需要在表dept.deptno上增加主键,再执行

    2. 通过子查询方式

      update emp
      set emp.dname = (select dept.dname from dept where dept.deptno = emp.deptno) 
      where exists
      (select dept.dname from dept where dept.deptno = emp.deptno)
      
    3. 使用merge into语句操作

      merge into emp
      using (select dname, deptno from dept where dept.dname in ('accounting','research')) dept
      on (dept.deptno = emp.deptno)
      when matched then
      update set emp.dname = dept.dname
      

      使用merge更新效率高,因为只对dept表进行了一次查询,如果用子查询方式update,则需要扫描两次dept