ora-30926:无法在oracle的合并查询中获取源表中的稳定行集

fquxozlt  于 2021-08-01  发布在  Java
关注(0)|答案(2)|浏览(374)

我真的不明白为什么下面的查询会出错 ORA-30926: unable to get a stable set of rows in the source tables 正如我所提供的 distinct 我的 merge 查询和bbètstèu历史具有适当的唯一约束。

merge into bb_tst_history h
using (select distinct r.ausuebungsbezeichnung
       from   bb_tst_rollup r
       join   ( select root, boerse, security_typ
                from   bb_export_filter
                minus
                select root, boerse, security_typ
                from   bb_tst_exception
              ) e
              on   r.root = e.root
              and  r.security_typ = e.security_typ
              and  r.boerse = e.boerse
      ) s
on (s.root = h.root and s.security_typ = h.security_typ and s.boerse = h.boerse)
when matched then
    update set h.ausuebungsbezeichnung = s.ausuebungsbezeichnung
when not matched then
    insert values (s.ausuebungsbezeichnung);
mitkmikd

mitkmikd1#

在中,必须有一条匹配条件的记录 USING 条款。
所以你可以用 GROUP BY 以及 MAXUSING 条款如下:

MERGE INTO BB_TST_HISTORY H
USING (
          SELECT MAX(R.AUSUEBUNGSBEZEICHNUNG) AS AUSUEBUNGSBEZEICHNUNG, 
                 R.ROOT, R.SECURITY_TYP, R.BOERSE
            FROM BB_TST_ROLLUP R
            JOIN (
              SELECT ROOT, BOERSE, SECURITY_TYP
                FROM BB_EXPORT_FILTER
              MINUS
              SELECT ROOT, BOERSE, SECURITY_TYP
                FROM BB_TST_EXCEPTION
          ) E
          ON R.ROOT = E.ROOT
             AND R.SECURITY_TYP = E.SECURITY_TYP
             AND R.BOERSE = E.BOERSE
         GROUP BY R.ROOT, R.SECURITY_TYP, R.BOERSE
      ) S ON ( S.ROOT = H.ROOT
   AND S.SECURITY_TYP = H.SECURITY_TYP AND S.BOERSE = H.BOERSE )
WHEN MATCHED THEN UPDATE
   SET H.AUSUEBUNGSBEZEICHNUNG = S.AUSUEBUNGSBEZEICHNUNG
WHEN NOT MATCHED THEN
INSERT VALUES ( S.AUSUEBUNGSBEZEICHNUNG );
k4ymrczo

k4ymrczo2#

发生此错误的原因是您在源中获取了多个用于连接列的行。处理此问题的最佳方法是,识别导致此问题的记录。下面的sql可以给你这些记录-

select root, security_typ, boerse, count(1) from
(select distinct r.AUSUEBUNGSBEZEICHNUNG from BB_TST_ROLLUP r,      
          (select ROOT, BOERSE, SECURITY_TYP from BB_EXPORT_FILTER minus 
select ROOT, BOERSE, SECURITY_TYP from BB_TST_EXCEPTION)) 
group by root, security_typ, boerse having count(1) > 1;

您需要更新“on”子句中的附加联接条件来修复此问题。
更新的合并语句-

merge into BB_TST_HISTORY h   using  
    (    select ROOT, BOERSE, SECURITY_TYP, AUSUEBUNGSBEZEICHNUNG from (select distinct r.AUSUEBUNGSBEZEICHNUNG from BB_TST_ROLLUP r       
        join     
          (select ROOT, BOERSE, SECURITY_TYP from BB_EXPORT_FILTER minus 
select ROOT, BOERSE, SECURITY_TYP from BB_TST_EXCEPTION))) e       
        on      r.root=e.root and r.security_typ=e.security_typ and r.boerse=e.boerse  ) s 
on (s.root=h.root and s.security_typ=h.security_typ and s.boerse=h.boerse) 
        when matched then   update set h.AUSUEBUNGSBEZEICHNUNG = s.AUSUEBUNGSBEZEICHNUNG
        when not matched then   insert values (s.AUSUEBUNGSBEZEICHNUNG);

相关问题