【问题标题】:Update/Merge with Duplicates in Destination Table (Oracle 11g)更新/合并目标表中的重复项 (Oracle 11g)
【发布时间】:2018-01-27 02:17:01
【问题描述】:

我一直在努力解决这个问题,希望得到一些建议。关于我正在使用的更新/合并查询中涉及的源表和目标表的一些上下文:

SRC Table

Format_Code     ACR
----------------------------
BAD             5  
SAD             7
MAD             2

SRC 是通过连接两个表的 select 语句创建的; select 语句看起来像这样:

Select distinct a.Format_Code, b.ACR from Formats a
Inner join Codes b on lower(a.Format_Name) = lower(b.Format_Name)

我正在尝试使用 SRC 更新目标表 (DES),在 Format_Code 上加入/匹配如下:

Merge Into Inventory DES
Using
(
Select distinct a.Format_Code, b.ACR from Formats a
Inner join Codes b on lower(a.Format_Name) = lower(b.Format_Name)
) SRC
On DES.Format_Code = SRC.Format_Code
When Matched Then Update set DES.ACR = SRC.ACR

我收到以下错误(因为我认为目标表中有重复项),但不确定如何忽略/绕过它们。 SRC 不包含重复项,但 DES 确实具有重复的 Format_Code。在更新期间,我想要么只更新重复行的一个实例,要么完全忽略重复(少量重复,因此我可以在必要时手动更新)

SQL Error: ORA-30926: unable to get a stable set of rows in the source tables
30926. 00000 -  "unable to get a stable set of rows in the source tables"
*Cause:    A stable set of rows could not be got because of large dml
activity or a non-deterministic where clause.
*Action:   Remove any non-deterministic where clauses and reissue the dml.

第一次发帖,如有错误请见谅

【问题讨论】:

  • 您确定这些实际上都是表格,而不是视图——其中一个引用了其他的?或者它们中的任何一个都没有触发器?它似乎适用于简单的表格。也许create an MCVE 这样我们就可以复制你所看到的。
  • 是的,SRC 的“表”实际上是视图,事实证明其中一个视图引用了我试图更新的同一个表。我已经在一个表中捕获了 SRC 查询的结果,然后在我的 Merge 语句中引用了它,它已经工作了。感谢您的帮助亚历克斯

标签: oracle11g merge duplicates


【解决方案1】:

...因为大量的 dml 活动...

尝试COMMIT,然后运行您的MERGE。有什么改善吗?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-07-13
    • 1970-01-01
    • 2012-08-31
    • 1970-01-01
    • 2013-11-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多