我有一個的SQL語句是這樣的:甲骨文11,更新加入
UPDATE tbl
SET old_ht = new_ht,
old_ttc = new_ttc
from table1 tbl
join table2 temp ON trim(temp.val_code) = trim(tbl.val_code)
AND trim(temp.tv_code) = trim(tbl.tv_code)
INNER JOIN table3 tbl3 ON trim(tbl3.oma_CODE) =trim(temp.oma_CODE)
AND trim(tbl3.men_CODE) =trim(temp.men_CODE)
AND trim(tbl3.gov_CODE) =trim(gov.BRD_CODE)
and tbl3.fld_id = tbl.fld_id ;
但似乎Oracle不支持此語法。
我也試過這樣:
UPDATE (select tbl.cost_ht as old_ht, temp.cost_ht as new_ht,tbl.cost_ttc as old_ttc
, temp.cost_ttc as new_ttc
from table1 tbl
join table2 temp ON trim(temp.val_code) = trim(tbl.val_code)
AND trim(temp.tv_code) = trim(tbl.tv_code)
INNER JOIN table3 tbl3 ON trim(tbl3.oma_CODE) =trim(temp.oma_CODE)
AND trim(tbl3.men_CODE) =trim(temp.men_CODE)
AND trim(tbl3.gov_CODE) =trim(gov.BRD_CODE)
and tbl3.fld_id = tbl.fld_id)
SET old_ht = new_ht, old_ttc = new_ttc
但我得到這個錯誤:
錯誤報告:
SQL Error:
ORA-01779: cannot modify a column which maps to a non key-preserved table 01779. 00000 - "cannot modify a column which maps to a non key-preserved table"
*Cause: An attempt was made to insert or update columns of a join view which map to a non-key-preserved table.
*Action: Modify the underlying base tables directly.
也許提供表的例子,說明你有什麼要做。 –
你的dbms抱怨,因爲它不認爲它保證只在你的選擇結果中看到每個tbl記錄。所以你不能更新這個視圖,而是必須更新表。 –