问题描述
嗨,康纳,克里斯等人,
您能否帮助我更好地理解何时对输入的非确定性行集提出ORA-30926?
高达12.1,它作为一个魅力,无论排序顺序和数量重复的行在输入ORA-30926被提出 (测试10.2.0.5,12.0,12.1)。
从12.2开始到19.4行为已更改,因此不会在每种情况下引发异常,而是合并2行。
提前谢谢你。
BR,
马丁·Z
您能否帮助我更好地理解何时对输入的非确定性行集提出ORA-30926?
高达12.1,它作为一个魅力,无论排序顺序和数量重复的行在输入ORA-30926被提出 (测试10.2.0.5,12.0,12.1)。
从12.2开始到19.4行为已更改,因此不会在每种情况下引发异常,而是合并2行。
提前谢谢你。
BR,
马丁·Z
drop table target purge; drop table source purge; create table target ( a number, b number ); create table source ( a number, b number ); insert into target values ( 1, 1 ); insert into source values ( 1, 1 ); insert into source values ( 1, 2 ); insert into source values ( 1, 3 ); --fails on ORA-30926: unable to get a stable set of rows in the source tables merge into target using (select * from source order by b desc) source on (target.a = source.a) when matched then update set target.b = source.b; --fails on ORA-30926: unable to get a stable set of rows in the source tables merge into target using (select * from source order by b asc) source on (target.a = source.a) when matched then update set target.b = source.b; --fails on ORA-30926: unable to get a stable set of rows in the source tables merge into target using source on (target.a = source.a) when matched then update set target.b = source.b; delete source where b = 3; --fails on ORA-30926: unable to get a stable set of rows in the source tables merge into target using (select * from source order by b desc) source on (target.a = source.a) when matched then update set target.b = source.b; --2 rows merged merge into target using (select * from source order by b asc) source on (target.a = source.a) when matched then update set target.b = source.b; --fails on ORA-30926: unable to get a stable set of rows in the source tables merge into target using source on (target.a = source.a) when matched then update set target.b = source.b; rollback; --2 rows merged merge into target using source on (target.a = source.a) when matched then update set target.b = source.b;复制
专家解答
这就是merge一直以来的工作方式。
我在11.2.0.4和19.3上看到完全相同的行为。除b asc从源顺序中选择 * 的语句外,所有语句都ORA-30926。
当它尝试两次更新同一行时,合并会引发ORA-30926。
如果要开始,你有
1,1
在目的地。和
1,1
1,2
源和合并按照该顺序处理源中的行。所以首先它设置
b = 1
这是它已经拥有的价值。所以这 “什么都不做”。然后下一行将其更新为2。所以只有目标中的行changes一次。
但是,如果您按照以下顺序处理源中的行:
1,2
1,1
首先你更新目标b = 2。然后应用第二行将其更新回1。这意味着该行现在已经changed twice。因此ORA-30926。
请注意,这意味着如果源中的所有行都具有相同的B值,则不会看到错误:
除非将order by添加到源查询,否则merge可以以任何顺序从源接收行。因此,如果您在从12.1 -> 19.4升级后开始看到这种行为,那是因为merge以不同的顺序接收行。例如,因为行的物理存储在升级过程中发生了变化。
如果这在您的应用程序中引起问题,您需要:
-在源查询中添加确定性排序以避免该问题
-确保目标中每一行的源中最多只有一行
我在11.2.0.4和19.3上看到完全相同的行为。除b asc从源顺序中选择 * 的语句外,所有语句都ORA-30926。
当它尝试两次更新同一行时,合并会引发ORA-30926。
如果要开始,你有
1,1
在目的地。和
1,1
1,2
源和合并按照该顺序处理源中的行。所以首先它设置
b = 1
这是它已经拥有的价值。所以这 “什么都不做”。然后下一行将其更新为2。所以只有目标中的行changes一次。
但是,如果您按照以下顺序处理源中的行:
1,2
1,1
首先你更新目标b = 2。然后应用第二行将其更新回1。这意味着该行现在已经changed twice。因此ORA-30926。
请注意,这意味着如果源中的所有行都具有相同的B值,则不会看到错误:
create table target ( a number, b number ); create table source ( a number, b number ); insert into target values ( 1, 1 ); insert into source values ( 1, 1 ); insert into source values ( 1, 1 ); insert into source values ( 1, 1 ); commit; merge into target using (select * from source order by b desc) source on (target.a = source.a) when matched then update set target.b = source.b; 3 rows merged.复制
除非将order by添加到源查询,否则merge可以以任何顺序从源接收行。因此,如果您在从12.1 -> 19.4升级后开始看到这种行为,那是因为merge以不同的顺序接收行。例如,因为行的物理存储在升级过程中发生了变化。
如果这在您的应用程序中引起问题,您需要:
-在源查询中添加确定性排序以避免该问题
-确保目标中每一行的源中最多只有一行
文章转载自ASKTOM,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。
评论
相关阅读
Oracle RAC 一键安装翻车?手把手教你如何排错!
Lucifer三思而后行
549次阅读
2025-04-15 17:24:06
【纯干货】Oracle 19C RU 19.27 发布,如何快速升级和安装?
Lucifer三思而后行
472次阅读
2025-04-18 14:18:38
Oracle SQL 执行计划分析与优化指南
Digital Observer
451次阅读
2025-04-01 11:08:44
XTTS跨版本迁移升级方案(11g to 19c RAC for Linux)
zwtian
445次阅读
2025-04-08 09:12:48
墨天轮个人数说知识点合集
JiekeXu
445次阅读
2025-04-01 15:56:03
【ORACLE】记录一些ORACLE的merge into语句的BUG
DarkAthena
439次阅读
2025-04-22 00:20:37
【ORACLE】你以为的真的是你以为的么?--ORA-38104: Columns referenced in the ON Clause cannot be updated
DarkAthena
414次阅读
2025-04-22 00:13:51
Oracle数据库一键巡检并生成HTML结果,免费脚本速来下载!
陈举超
414次阅读
2025-04-20 10:07:02
Oracle 19c RAC更换IP实战,运维必看!
szrsu
394次阅读
2025-04-08 23:57:08
【活动】分享你的压箱底干货文档,三篇解锁进阶奖励!
墨天轮编辑部
359次阅读
2025-04-17 17:02:24