----- s.op_id= ------
| S |----------| OP |
----- op.op_id ------
|
| op.op_id = j.op_id
|
-----
| J |
-----
oracle数据库有三个表journey
,op_profile
和special
。
journey
有两列journey_id
(主键)和op_id
,
op_profile
有主键op_id
和
special
在op_id
上有一个op_profile
列外键,另一列s_id
是表主键。
我尝试使用以下sql usin sql developer将所有op_id
列更新为等于journey_id
表的journey
列:
UPDATE (SELECT special.op_id, journey.journey_id, op_profile.op_id AS op
FROM special, journey, op_profile
WHERE special.op_id = journey.op_id AND journey.op_id = op_profile.op_id)
SET op_id = journey_id, op = journey_id;
会出现以下错误
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.
似乎说这个操作由于每个表的键而失败。
这可能是这样还是另一种?
答案 0 :(得分:2)
是的,可以使用两个更新语句:
update s
set op_id = (select j.journey_id
from j
where j.op_id = s.op_id
);
和
update op
set op_id = (select j.journey_id
from j
where j.op_id = op.op_id
);
答案 1 :(得分:0)
在以下内容上添加索引(如果之前不可用)
如果无法获取一组稳定的更新行,则会出现此问题。