热门标签 | HotTags
当前位置:  开发笔记 > 数据库 > 正文

ORA-02055:distributedupdateoperationfailed;rollbackreq

ORA-02055:distributedupdateoperationfailed;rollbackrequired

ORA-02055: distributed update operation failed; rollback required

最近同事遇到一个奇怪的问题求助,以下奉上国外大神的问题重现及解决方法

--------------------------------------------------------------

ORA-02055: distributed update operation failed; rollback required


--------------------------------------------------------------

You call a remote procedure or package over a database link.

Now, on the other side (the remote side), there was an error encountered, but there were already some statements executed successfully.

Now you will need to perform a rollback before you can do a select on the calling side, or you will get this error.

原因:通过数据库链接调用远程存储过程或包。然而,执行过程中远程数据库有报错,,但是部分语句已成功执行

措施:在调用端可以查询之前,需要执行回滚操作,否则将获得以上错误提示。

问题重现:

-- First we create some test users

SQL> drop user test1 cascade;

User dropped.

SQL> drop user test2 cascade;

SQL> create user test1 identified by test1;

User created.

SQL> create user test2 identified by test2;

User created.

SQL> grant create session, create table, create trigger, create procedure, create database link to test1, test2;

Grant succeeded.

SQL> alter user test1 quota unlimited on system;

User altered.

SQL> alter user test2 quota unlimited on system;

User altered.

Now we connect to test 2 (remote user) and create a table

SQL> conn test2/test2@XE
Connected.

SQL> create table test2_tab(n number);

Table created.

SQL> insert into test2_tab values(1);

1 row created.

SQL> commit;

Commit complete.

In order to demonstrate this error, we create a trigger on the newly created table, but make sure the trigger fails. In our case, we assign a character to a number field:
create or replace trigger test2_tab_bir
before insert on test2_tab
for each row
begin
:new.n := 'a';
end;
/

Trigger created.

Connect to test1, create database link
SQL> conn test1/test1@XE
Connected.
SQL>

SQL> create database link test2 connect to test2 identified by test2 using 'XE';

Database link created.

Now we will create a procedure which will first do a successful dml, after that a dml that fails due to the incorrect trigger:
create or replace procedure p is
begin
-- first do a statement that executes ok
update test2_tab@test2 set n=2;
-- next statement will fail because of the invalid trigger
insert into test2_tab@test2 values(1);
end;
/

Procedure created.

Call the procedure, it will fail:
SQL> exec p
BEGIN p; END;

*
ERROR at line 1:
ORA-02055: distributed update operation failed; rollback required
ORA-06502: PL/SQL: numeric or value error: character to number conversion error
ORA-06512: at "TEST2.TEST2_TAB_BIR", line 2
ORA-04088: error during execution of trigger 'TEST2.TEST2_TAB_BIR'
ORA-02063: preceding 3 lines from TEST2
ORA-06512: at "TEST1.P", line 4
ORA-06512: at line 1

Now we have a failed distributed transaction, you need to rollback, else you will get the error when selecting ANY table/view
SQL> select sysdate from dual;
select sysdate from dual
*
ERROR at line 1:
ORA-02067: transaction or savepoint rollback required

-- also happens when Oracle itself calls another select recursively (notice the ORA-00604)

SQL> select * from user_2pc_pending;
select * from user_2pc_pending
*
ERROR at line 1:
ORA-00604: error occurred at recursive SQL level 1
ORA-02067: transaction or savepoint rollback required
-----------------------------------

Present By Dylan.

linux

推荐阅读
  • 本文详细介绍如何使用Python进行配置文件的读写操作,涵盖常见的配置文件格式(如INI、JSON、TOML和YAML),并提供具体的代码示例。 ... [详细]
  • 1:有如下一段程序:packagea.b.c;publicclassTest{privatestaticinti0;publicintgetNext(){return ... [详细]
  • 本文探讨了适用于Spring Boot应用程序的Web版SQL管理工具,这些工具不仅支持H2数据库,还能够处理MySQL和Oracle等主流数据库的表结构修改。 ... [详细]
  • 本文详细介绍了如何通过多种编程语言(如PHP、JSP)实现网站与MySQL数据库的连接,包括创建数据库、表的基本操作,以及数据的读取和写入方法。 ... [详细]
  • 在当前众多持久层框架中,MyBatis(前身为iBatis)凭借其轻量级、易用性和对SQL的直接支持,成为许多开发者的首选。本文将详细探讨MyBatis的核心概念、设计理念及其优势。 ... [详细]
  • 在使用 DataGridView 时,如果在当前单元格中输入内容但光标未移开,点击保存按钮后,输入的内容可能无法保存。只有当光标离开单元格后,才能成功保存数据。本文将探讨如何通过调用 DataGridView 的内置方法解决此问题。 ... [详细]
  • 本文详细介绍了如何在 Linux 平台上安装和配置 PostgreSQL 数据库。通过访问官方资源并遵循特定的操作步骤,用户可以在不同发行版(如 Ubuntu 和 Red Hat)上顺利完成 PostgreSQL 的安装。 ... [详细]
  • 如何在PostgreSQL中查看数据表
    本文将指导您使用pgAdmin工具连接到PostgreSQL数据库,并展示如何浏览和查找其中的数据表。通过简单的步骤,您可以轻松访问所需的表结构和数据。 ... [详细]
  • 利用存储过程构建年度日历表的详细指南
    本文将介绍如何使用SQL存储过程创建一个完整的年度日历表。通过实例演示,帮助读者掌握存储过程的应用技巧,并提供详细的代码解析和执行步骤。 ... [详细]
  • 本文介绍了如何通过 Maven 依赖引入 SQLiteJDBC 和 HikariCP 包,从而在 Java 应用中高效地连接和操作 SQLite 数据库。文章提供了详细的代码示例,并解释了每个步骤的实现细节。 ... [详细]
  • 在使用SQL Server进行动态SQL查询时,如果遇到LIKE语句无法正确返回预期结果的情况,通常是因为参数传递方式不当。本文将详细探讨这一问题,并提供解决方案及相关的技术背景。 ... [详细]
  • 本文介绍如何通过创建替代插入触发器,使对视图的插入操作能够正确更新相关的基本表。涉及的表包括:飞机(Aircraft)、员工(Employee)和认证(Certification)。 ... [详细]
  • MySQL缓存机制深度解析
    本文详细探讨了MySQL的缓存机制,包括主从复制、读写分离以及缓存同步策略等内容。通过理解这些概念和技术,读者可以更好地优化数据库性能。 ... [详细]
  • SQLite 动态创建多个表的需求在网络上有不少讨论,但很少有详细的解决方案。本文将介绍如何在 Qt 环境中使用 QString 类轻松实现 SQLite 表的动态创建,并提供详细的步骤和示例代码。 ... [详细]
  • 精选30本C# ASP.NET SQL中文PDF电子书合集
    欢迎订阅我们的技术博客,获取更多关于C#、ASP.NET和SQL的最新资讯和资源。 ... [详细]
author-avatar
blankworld
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有