zoukankan      html  css  js  c++  java
  • Merge into用法

    简单的说就是,判断表中有没有符合on()条件中的数据,有了就更新数据,没有就插入数据。  

    有一个表T,有两个字段a、b,我们想在表T中做Insert/Update,如果条件满足,则更新T中b的值,否则在T中插入一条记录。

    merge into 目标表 a
     
    using 源表 b
     
    on(a.条件字段1=b.条件字段1 and a.条件字段2=b.条件字段2 ……)  
     
    when matched then update set a.更新字段=b.字段
     
    when  not matched then insert into a(字段1,字段2……)values(值1,值2……)
    MERGE INTO USER UOR_0
    USING (SELECT COUNT(1) AS ROW_COUNT
             FROM USER
            WHERE UOR_USER_ID = '2019052811'
              AND UOR_ORG_ID = '000002') UOR_1
    ON (UOR_1.ROW_COUNT > 0)
    WHEN MATCHED THEN
      UPDATE
         SET UOR_0.UDR_CREATE_USER_ID = 'admin',
             UOR_0.UDR_CREATE_DATE    = SYSDATE,
             UOR_0.UDR_UPDATE_USER_ID = 'admin',
             UOR_0.UDR_UPDATE_DATE    = SYSDATE,
             UOR_0.UDR_RECORD_STATUS  = '10'
       WHERE UOR_USER_ID = '2019052811'
         AND UOR_ORG_ID = '000002'
    WHEN NOT MATCHED THEN
      INSERT
        (UOR_0.UOR_USER_ID,
         UOR_0.UOR_ORG_ID,
         UOR_0.UDR_CREATE_USER_ID,
         UOR_0.UDR_CREATE_DATE,
         UOR_0.UDR_UPDATE_USER_ID,
         UOR_0.UDR_UPDATE_DATE,
         UOR_0.UDR_RECORD_STATUS)
      VALUES
        ('2019052811', '000002', 'admin', SYSDATE, 'admin', SYSDATE, '10')
      
  • 相关阅读:
    手机电阻式和电容式触摸屏九大区别
    AMBA、AHB、APB总线简介
    PHY芯片
    S3C2440A Memory design
    ARM、DSP、FPGA的技术特点和区别
    LPC2104的Boot与Remap详解(一)
    Memorymapped I/O
    Motherboard Chipsets and the Memory Map
    88f6282 notes
    太网设计FAQ:以太网MAC和PHY
  • 原文地址:https://www.cnblogs.com/25miao/p/10937442.html
Copyright © 2011-2022 走看看