【发布时间】:2019-10-23 14:20:17
【问题描述】:
我的查询在 MySQL 上运行良好,但如果我在 Oracle 数据库中执行它,我会收到以下错误:
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
MySQL 查询:
UPDATE T1
INNER JOIN T2 ON T1.UIDPK =T2.UIDFK
SET T1.C1=CONCAT('EMPTY_',T2.UID) WHERE T2.C1 IS NULL ;
更改了对 Oracle 的查询:
UPDATE
(
SELECT T1.C1 AS OLD ,CONCAT('EMPTY_',T2.UID) AS NEW FROM T1
INNER JOIN T2 ON T1.UIDPK= T2.UIDFK WHERE T1.C1 IS NULL
) T3
SET T3.OLD = T3.NEW
以上查询在 Oracle 数据库中不起作用。
【问题讨论】:
标签: sql oracle sql-update inner-join