merge into copy_emp1 c
  using employees e
  on (c.employee_id=e.employee_id)
when matched then
  update set
  c.first_name=e.first_name,
  c.last_name=e.last_name,
  c.email=e.email,
  c.phone_number=e.phone_number,
  c.hire_date=e.hire_date,
  c.job_id=e.job_id,
  c.salary=e.salary,
  c.commission_pct=e.commission_pct,
  c.manager_id=e.manager_id,
  c.department_id=e.department_id
when not matched then
  insert values(e.employee_id,e.first_name,e.last_name,e.email,e.phone_number,
  e.hire_date,e.job_id,e.salary,e.commission_pct,e.manager_id,e.department_id)

注意:被on关联的列(employee_id)不能被更新,否则会报错ORA-38104:无法

更新on子句中引用的列。

--实验
JOHN@ ora10g> select * from jobs;

JOB_ID     JOB_TITLE    MIN_SALARY MAX_SALARY
---------- ------------ ---------- ----------
ad_pres    vp                20000      40000
fi_account accountant         4200       9000
st_clerk   stock clerk        2000       5000
it_prog    programmer         4000      10000
dba        db admin           4200       9000

JOHN@ ora10g> select * from jobs_acquisition;

JOB_ID     JOB_TITLE    MIN_SALARY MAX_SALARY
---------- ------------ ---------- ----------
ad_pres    vp                10000      40000
dba        db admin           4200       9000

JOHN@ ora10g> merge into jobs j
  2  using (select * from jobs_acquisition) a
  3  on (j.job_id=a.job_id)
  4  when matched then
  5  update set
  6  j.job_title=a.job_title,
  7  j.min_salary=a.min_salary,
  8  j.max_salary=a.max_salary
  9  when not matched then
 10  insert (j.job_id, j.job_title, j.min_salary, j.max_salary)
 11  values (a.job_id, a.job_title, a.min_salary, a.max_salary);

JOHN@ ora10g> select * from jobs;

JOB_ID     JOB_TITLE    MIN_SALARY MAX_SALARY
---------- ------------ ---------- ----------
ad_pres    vp                10000      40000
fi_account accountant         4200       9000
st_clerk   stock clerk        2000       5000
it_prog    programmer         4000      10000
dba        db admin           4200       9000

JOHN@ ora10g> select * from jobs_acquisition;

JOB_ID     JOB_TITLE    MIN_SALARY MAX_SALARY
---------- ------------ ---------- ----------
ad_pres    vp                10000      40000
dba        db admin           4200       9000

最新文章

  1. Android学习
  2. 图论 ---- spfa + 链式向前星 ---- poj 3268 : Silver Cow Party
  3. docker swarm compose
  4. Java [Leetcode 40]Combination Sum II
  5. c#.net与vb.net中读写Cookie的方法!
  6. java根据url获取json对象
  7. nginx新手入门
  8. java学习笔记 --- 多态
  9. less基础语法
  10. easyui datagrid 排序问题
  11. 类的父类object的一些属性、方法
  12. java循环1
  13. 决策树之ID3,C4.5及CART
  14. CPU-bound(计算密集型) 和I/O bound(I/O密集型)
  15. [Android]_[0基础]_[adb 有用命令]
  16. ftp使用(图文详解)
  17. #2007. 「SCOI2015」国旗计划
  18. kafka java API的使用
  19. CF359D:Pair of Numbers——题解
  20. 【线段树】POJ3225-Help with Intervals

热门文章

  1. BZOJ5324 & 洛谷4563 & LOJ2545:[JXOI2018]守卫——题解
  2. 洛谷 P4592 [TJOI2018]异或 解题报告
  3. 洛谷 P4555 [国家集训队]最长双回文串 解题报告
  4. 四连测Day1
  5. CCPC-Winter Camp div2 day5
  6. 002.比较vector对象是否相等
  7. Rsync+inotify自动同步数据
  8. ListView - SimpleAdapter 行间颜色交替(转)
  9. 图论:Prufer编码
  10. [洛谷P1707] 刷题比赛