2014-02-21 61 views
3

我有這樣的合併報表時,以獲得在源表穩定組的列:ORA-30926:無法合併表

MERGE INTO TB_DP_REGIAO B 
USING TMP_DP_REGIAO P 
ON (P.DS_PROTHEUS_CODE = B.DS_PROTHEUS_CODE) 
WHEN MATCHED THEN UPDATE SET B.DS_PLANNING_CODE = CASE WHEN B.DT_LOAD < P.DT_LOAD THEN P.DS_PLANNING_CODE ELSE B.DS_PLANNING_CODE END, 
          B.DT_LOAD = CASE WHEN B.DT_LOAD < P.DT_LOAD THEN P.DT_LOAD ELSE B.DT_LOAD END 
WHEN NOT MATCHED THEN INSERT(B.DS_PROTHEUS_CODE, B.DS_PLANNING_CODE, B.DT_LOAD) VALUES(P.DS_PROTHEUS_CODE, P.DS_PLANNING_CODE, P.DT_LOAD); 

即返回我這個錯誤:

Error starting at line 1 in command: 
MERGE INTO TB_DP_REGIAO B 
USING TMP_DP_REGIAO P 
ON (P.DS_PROTHEUS_CODE = B.DS_PROTHEUS_CODE) 
WHEN MATCHED THEN UPDATE SET B.DS_PLANNING_CODE = CASE WHEN B.DT_LOAD < P.DT_LOAD THEN P.DS_PLANNING_CODE ELSE B.DS_PLANNING_CODE END, 
          B.DT_LOAD = CASE WHEN B.DT_LOAD < P.DT_LOAD THEN P.DT_LOAD ELSE B.DT_LOAD END 
WHEN NOT MATCHED THEN INSERT(B.DS_PROTHEUS_CODE, B.DS_PLANNING_CODE, B.DT_LOAD) VALUES(P.DS_PROTHEUS_CODE, P.DS_PLANNING_CODE, P.DT_LOAD) 
Error report: 
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. 

當目標表是空的,它的工作原理。如果我在P.DT_LOADB.DT_LOAD相同的情況下運行它,它可以工作。當我第二天運行它時,當P.DT_LOAD提前一天時,我得到這個錯誤。

有人可以幫助我嗎?

在此先感謝!

+3

我想這意味着你在'using'子句中有多個匹配。您可能需要預先編制'TMP_DP_REGIAO'。 –

+2

嘗試:使用(從TMP_DP_REGIAO選擇不同的colx,coly,...)P – tbone

+0

@GordonLinoff就是這樣!謝謝你的幫助! –

回答

6

這是一個棘手的案件。主要原因是您似乎在TMP_DP_REGIAO.DS_PROTHEUS_CODE列中有重複項,而MERGE嘗試多次更新同一行目標表。但是,如果在更新的列的新值和舊值相同,Oracle可以跳過重複這個問題:

SQL> select * from t; 

     CODE TEXT                 
---------- ----------               
     1 test                 

SQL> merge into t using (
    2 select 1 code,'test' text from dual union all 
    3 select 1 code,'test' text from dual 
    4 ) s 
    5 on (t.code = s.code) 
    6 when matched then 
    7 update set t.text = s.text 
    8/

2 rows merged 

但如果新舊值是不同的Oracle提高你得到的異常:

SQL> merge into t using (
    2 select 1 code,'a' text from dual union all 
    3 select 1 code,'a' text from dual 
    4 ) s 
    5 on (t.code = s.code) 
    6 when matched then 
    7 update set t.text = s.text 
    8/
merge into t using (
      * 
error in line 1: 
ORA-30926: unable to get a stable set of rows in the source tables 
+0

就是這樣!謝謝你的幫助! –

0

此問題的另一個原因也可能是ON子句中指定的條件。出現此錯誤時,分別有1對多的映射到您的目標行與源行可能是由於兩個原因。

1) there are duplicate rows in source table. 
2) there are unique rows in source table, but ON clause conditions are pointing to multiple rows in the source table. 

在第二種情況下,ON子句的條件已經修飾分別實現在目的地和源表1對1或多對一映射。