create or replace procedure TESTDT(V_ID1 IN NUMBER, V_ID2 IN NUMBER) is
begin
update tlink set status = 'SUCCEED'
where tid= V_ID1;
COMMIT;
update tlink set status = 'SUCCEED'
where tid= V_ID2;
update bobo.tlink@db2
set status = 'SUCCESS'
where tid = v_id2;
end TESTDT;
DB1上调用该存储过程。
SQL> exec bobo.testdt@db2(1,2);
PL/SQL 过程已成功完成。
SQL> exec bobo.testdt@db2(1,2);
BEGIN bobo.testdt@db2(1,2); END;
*
第 1 行出现错误:
ORA-02046: distributed transaction already begun
ORA-06512: 在 line 1SQL> select * from bobo.tlink@db2;
SQL> select * from bobo.tlink@db2
*
第 1 行出现错误:
ORA-02046: distributed transaction already begun
ORA-02063: 紧接着 line (起自 DB2)
对该错误的解决方法: 不要在远程调用的存储过程或者包中使用事务控制语句。因为远程调用的包执行时没有机制执行2-phase commit.
事务控制语句应该在发起事务的节点执行。来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/10522540/viewspace-660229/ ,如需转载,请注明出处,否则将追究法律责任。