问题描述
我正在尝试复制 Ingres从 tbl2 更新 tbl1"命令,该命令在 Oracle 中并不完全存在.
I'm trying to replicate an Ingres "update tbl1 from tbl2" command, which doesn't exactly exist in Oracle.
所以我使用更新(选择 tbl1 加入 tbl2...)"命令.两个表都定义了主键,我认为我的连接是唯一标识行,但我仍然收到ORA-01779:无法修改映射到非键保留表的列".
So I use "update (select tbl1 join tbl2...)" command. Both tables have primary keys defined and I thought that my join was uniquely identifying rows, but I'm still getting "ORA-01779: cannot modify a column which maps to a non key-preserved table".
以下是适当的匿名表定义和我尝试执行的更新:
Here are suitably anonymized table definitions and the update I'm trying to execute:
如何定义我的选择,以便 Oracle 对我没有违反唯一性感到满意?
How can I define my select such that Oracle will be satisfied that I have no uniqueness violations?
推荐答案
您应该能够使用相关子查询来做到这一点
You should be able to do this with a correlated subquery
您编写的 UPDATE
的问题在于 Oracle 无法保证有 1 个 tbl2.c
值对应于单个 tbl1.b
值.如果tbl2
中有多个行用于tbl1
中的任何特定行,则相关更新将抛出一个错误,表明单行子查询返回了多行.在这种情况下,您需要向子查询添加一些逻辑,以指定在这种情况下使用 tbl2
中的哪一行.
The problem with the UPDATE
that you've written is that Oracle cannot guarantee that there is exactly 1 tbl2.c
value that corresponds to a single tbl1.b
value. If there are multiple rows in tbl2
for any particular row in tbl1
, the correlated update is going to throw an error indicating that a single-row subquery returned multiple rows. In that case, you'd need to add some logic to the subquery to specify which row from tbl2
to use in that case.
这篇关于Oracle - 更新连接 - 非键保留表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!