merge into ORA-30926
同時(shí)要求在一張表中添加一個(gè)字段,由于數(shù)據(jù)量較大,想使用merge into update的方式將數(shù)據(jù)
meger into xxx1 t1 using(select * from xxx2 )t2? on(t1.xm=t2.xm and t1.dz=t2.dz) when matched then update? set train_time=d_time; commit;
執(zhí)行了兩個(gè)小時(shí)后 報(bào)錯(cuò):ORA-30926:?無法在源表中獲得一組穩(wěn)定的行
后來網(wǎng)上查找資料meger into on 字段應(yīng)給是唯一值
首先我們要知道m(xù)erge into存在的意義是什么!!!
??????使用merge into??是為了根據(jù)匹配條件on(condition)利用table_source 的數(shù)據(jù)更新合并table_target的數(shù)據(jù)。
merge into 的內(nèi)部處理是將table_source?的每一條記錄和table_target的每一條記錄對(duì)比匹配,匹配到符合條件的??記錄就會(huì)進(jìn)行修改,匹配不到的話就會(huì)insert。如果table_source的匹配列中有重復(fù)值的話,等到第二次重復(fù)的列值匹配的時(shí)候,就會(huì)將第一次的update后的值再一次update,就是說合并后的table_target中會(huì)丟失在table_source中的記錄!!!如果記錄丟失的話,兩表合并的意義何在?!!因此我們使用merge into要注意:源表匹配列中不能有重復(fù)值,否則無法匹配(報(bào)錯(cuò)!?????)。
???查詢一下ORA-30926錯(cuò)誤的具體說明:
Oracle Error : ORA-30926
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.
?
If there is either a many-to-one or many-to-many relationship between the source and target tables. This is not as serious as it sounds because you would normally have to MERGE a one-to-one or one-to-zero relationship as your join condition would be protected by the target's primary key.
When performing a merge statement, the table to be merged had multiplerecords with the same key used for matching. While this is ok forrecords to be inserted into the target table, Oracle doesn't like thison the update portion of the statement. The solution is to remove the duplicate or pick a matching key that is truely unique.
?
There is a restriction that multiple updates to the same row in the destination table is not allowed.?ORA-30926 error will be returned if this is attempted.
?
??? 通過上面的信息可以得知,對(duì)目標(biāo)表中的相同行數(shù)據(jù)進(jìn)行多次更新是不允許的,這樣會(huì)導(dǎo)致ORA-30926錯(cuò)誤。
?
??? 追溯代碼,確保MERGE INTO中USING表對(duì)于ON中的關(guān)聯(lián)條件是唯一的,注意到表DW.FACT_DEAL_AUCTION_D的數(shù)據(jù)是細(xì)化到AUCTION_ID的,會(huì)存在多條相同的CUSTID和CATID維度數(shù)據(jù)。通過使用group by修改代碼即可解決。
總結(jié)
以上是生活随笔為你收集整理的merge into ORA-30926的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 分手后梦到对方算是缘尽吗
- 下一篇: 谈Find指令