2012-04-17 189 views
-1

我有一個沒有任何唯一鍵列的表,我想用自連接執行批量更新。Oracle中的批量更新給出了錯誤ORA-01779

Update 
(
select t1.Col1 col1, t2.col1 col2 
from table t1 
inner join table t2 on <join condtn> 
where <condtn> 
) 
Set col1 = col2 

但由於表沒有唯一鍵列,它提供了錯誤:

ORA-01779: cannot modify a column which maps to a non key-preserved table.

難道還有比添加唯一約束:)

+0

你有一堆問題已被回答,並已明顯你幫了你,但你還沒有[接受他們](http://u.sbhat.me/t6SXUH)。其他人也許不會傾向於幫助你。 – Sathya 2012-04-18 05:40:54

回答

3

其他任何解決方案,您應該能夠重構查詢做相關的更新

UPDATE table t1 
    SET col1 = (SELECT col1 
       FROM table t2 
       WHERE t1.<<some column>> = t2.<<some column>>) 
WHERE EXISTS(SELECT 1 
       FROM table t2 
       WHERE t1.<<some column>> = t2.<<some column>>)