merge into 语句就是insert和update的一个封装,简单来说就是:

 有则更新,无则插入

下面说怎么使用

MERGE INTO table_Name  T1(匿名)

using (另外一张表,或者是查询出来的部分数据)T2

on(条件)   注意:ON条件里的字段在后面是不能操作的,(epm.ID=T2.ID),那么在后面无论更新和操作都不能对emp.ID进行

when matched then

  语句1,

  语句2  (最后不能有分号)

when  not  matched then

 语句1,

 语句2;

下面是例子:

 --利用merge into语法往表中插入数据
  MERGE INTO DIM_TIME  T1
  USING (SELECT DATE'2013-1-1'+(ROWNUM-1) as Date_Name FROM dual CONNECT BY rownum <=
  (date'2014-1-1'-date'2013-1-1')) temp_Date
  on (T1.Date_Name =temp_Date.Date_Name)
  when  matched then
    update set T1.Date_ID=to_char(temp_Date.Date_Name,'YYYYMMDD')
  when not matched then
   insert (DATE_ID) values(to_char(temp_Date.Date_Name,'YYYYMMDD'));

 

 

  

 

相关文章:

  • 2021-05-27
  • 2021-10-25
  • 2021-06-20
  • 2022-12-23
  • 2021-11-02
  • 2021-12-21
猜你喜欢
  • 2021-06-07
  • 2021-11-30
  • 2022-12-23
  • 2022-12-23
  • 2021-11-09
  • 2022-12-23
相关资源
相似解决方案