今天,开发人员在调用远端数据库的过程truncate表的时候,oracle提示 ORA-02064,
查询了一下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.
我们业务的实现: 过DBLINK调用远程数据库的存储过程,进行TRUNCATE TABLE,并返回成功与否的标志。
根据oracle文档的描述,问题应该出在返回标志的问题上,我试了一下,如果,不用返回参数的时候,过程可以成功执行,如果加上返回参数,则提示ORA-02064
应该是oracle认为远程调用过程,执行和返回标志是一个完整的事务,如果要返回到远端,那么就破坏了事务的完整性,所以提示ORA-02064
这个问题的解决办法有两个:1.不要返回标志,根据过程是否成功执行,在本地做判断,2.在远端的过程中加入 PRAGMA AUTONOMOUS_TRANSACTION; 这句话,制定义事务.
修改后的过程,如下
CREATE OR REPLACE PROCEDURE P_EXECUTE_DDL(AN_O_RET_CODE OUT NUMBER,
AC_O_RET_MSG OUT VARCHAR2,
AC_I_DDL IN VARCHAR2) IS
PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
AC_O_RET_MSG := '操作成功';
AN_O_RET_CODE := 0;
EXECUTE IMMEDIATE AC_I_DDL;
EXCEPTION
WHEN OTHERS THEN
ROLLBACK;
AN_O_RET_CODE := -1;
AC_O_RET_MSG := '错误代码:' || SQLCODE || CHR(13) || '错误信息:' || SQLERRM;
END P_EXECUTE_DDL;
这样就可以远程调用了,清空远程的表了.
在这里要感谢 蜗牛,songsong 对本人的支持,非常感谢,让我又学到了一招:)!!!!!!!!