尝试合并时合并条件在oracle中不起作用

我有一张桌子,

--------------
|id   descrip |
|1  A         |
|2  B         |
|3  C         |
|3  D         |
|3  E         |
|4  F         |
|4  F         |

我的预期输出是:

--------------
|id descrip |
|1  A       |
|2  B       |
|3C C       |
|3D D       |
|3E E       |
|4  F       |
|4  F       |

我尝试使用第一种方法:

merge into rules_table a
using rules_table b
on (a.id = b.id and a.descrip and a.rowid > b.rowid)
when matched then
  update set a.id = b.id || b.descrip

我尝试的第二种方法是:

update rules_table a
   set a.id =
       (select b.id || b.descrip
          from rules_table b
         where b.id = a.id
           and b.descrip = a.descrip
           and a.rowid = b.rowid)

但是,我没有得到想要的输出。

servicesp417 回答:尝试合并时合并条件在oracle中不起作用

根据您的预期结果,我认为您正在寻找以下内容:

University

以下内容也应该起作用:

MERGE INTO rules_table a
USING (SELECT rowid,id,descrip,COUNT(DISTINCT descrip) over (PARTITION BY id) cnt
         FROM rules_table) b
 ON (a.rowid = b.rowid AND b.cnt > 1)
 WHEN MATCHED THEN UPDATE 
  SET a.id=b.id||b.descrip
本文链接:https://www.f2er.com/3153861.html

大家都在问