zoukankan      html  css  js  c++  java
  • Oracle 合并 merger into

    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

  • 相关阅读:
    Varnish常用相关命令工具
    Varnish介绍
    varnish 内置函数详细说明
    job console部署
    Windows Server 2008(R2)配置apache+php+mysql环境问题事项
    Eclipse for php + Xdebug搭建PHP的调试环境
    DB2 SQL Error: SQLCODE=-805, SQLSTATE=51002 解决方法
    base64加密解密
    将输入流InputStream转换为String
    PowerDesigner16 安装包及破解文件
  • 原文地址:https://www.cnblogs.com/john2017/p/6371615.html
Copyright © 2011-2022 走看看