解决:ORA-02064 distributed operation not supported

起因:
近日项目需要通过Oracle DBLink调用远程数据库的存储过程。
即:数据库A ,B 通过DBlink互相访问, 数据库A调用数据库B的存储过程pro_b , pro_b里面有DML语句,且有commit ,或rollback. 这时数据库A通过DBlink 的调用pro_b@B就会产生这个错误:
Caused by: java.sql.SQLException: ORA-02064: distributed operation not supported

原因:
查询了一下oracle文档,对于这个错误的描述如下:

ORA-02064 distributed operation not supported
Cause:One of the following unsupported operations was attempted:
Array execute of a remote update with a subquery that references a database link, or
An update of a long column with bind variable and an update of a second column with a subquery that both references a database link and a bind variable, or
A commit is issued in a coordinated session from an RPC with OUT parameters.
Action:Simplify the remote update statement.

数据库A通过Oracle DBLink到另一个数据库B,调用了对方(B)的存储过程时,如果该存储过程中有更新(DDL)数据的操作,则会有ora-02064不支持分布式

解决方法:
在不修改数据库B,pro_b的业务逻辑的情况下有两种方法可以解决:

1.在被调的存储过程(pro_b)中,增加一个传入参数,且增加判断逻辑,如果来自数据库A的调用则不要commit,rollback数据库事务操作,如果是来自本地的调用继续沿用之前的逻辑。

2.用Oracle自治事务来解决。在数据库A中的procedure中添加oralce自治事务的声明方法为:
PRAGMA AUTONOMOUS_TRANSACTION。

发布了22 篇原创文章 · 获赞 35 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/sinat_27431397/article/details/103561558