dblink手动执行成功,存储过程中报错

环境oracle 9.2.0.8
HP UX 11i

创建dblink
create database link anlink connect to xxxx identified by xxxx using 'gghw';


创建存储过程

SQL> CREATE OR REPLACE PROCEDURE prc_an
  2  IS
  3  BEGIN
  4  EXECUTE IMMEDIATE ('truncate table an');
  5  insert into an select * from user_tables@anlink;
  6  commit;
  7  END prc_an;
  8  /

Warning: Procedure created with compilation errors.


报错信息

SQL> show error
Errors for PROCEDURE PRC_AN:

LINE/COL ERROR
-------- -----------------------------------------------------------------
5/1      PL/SQL: ORA-04052: error occurred when looking up remote object
         SYS.USER_TABLES@ANLINK
         ORA-00604: error occurred at recursive SQL level 1
         ORA-04029: error ORA-980 occurred when querying
         ORA_KGLR7_DEPENDENCIES
         ORA-00604: error occurred at recursive SQL level 1
         ORA-00980: synonym translation is no longer valid
         ORA-02063: preceding 3 lines from ANLINK

5/1      PL/SQL: SQL Statement ignored


手动执行成功
SQL> insert into an select * from user_tables@anlink;

127 rows created.

SQL> commit;

Commit complete.

 

解决方法:

SQL> create view v_an as select * from user_tables@anlink;

视图已创建。

SQL> CREATE OR REPLACE PROCEDURE prc_an
  2  IS
  3  BEGIN
  4  EXECUTE IMMEDIATE ('truncate table an');
  5  insert into an select * from v_an;
  6  commit;
  7  END prc_an;
  8  /

过程已创建。

SQL> exec prc_an;

PL/SQL 过程已成功完成。

SQL> select count(*) from an;

  COUNT(*)
----------
       127

SQL> truncate table an;

表被截断。

SQL> exec prc_an;

PL/SQL 过程已成功完成。

SQL> select count(*) from an;

  COUNT(*)
----------
       127

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/13165828/viewspace-610009/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/13165828/viewspace-610009/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值