ORA-06508: PL/SQL: 找不到被调用的程序单元

2021-12-06 00:00:00 anonymous oracle plsql

我使用的是 oracle 10g 和 toad 11.5.我正在尝试从匿名块调用 api.

I am using oracle 10g and toad 11.5. I am trying to call an api from an anonymous block.

如果我在添加dbms_output.put_line后重新编译api,然后尝试执行匿名块,它会显示错误:

If I recompile the api after adding dbms_output.put_line and then try to execute the anonymous block, it shows error as:

"ORA-06508: PL/SQL: could not find program unit being called".

但是,如果我结束当前会话并打开一个新会话,则匿名块将执行而不会出错.

However if I end current session and open a new session, then the anonymous block will execute with out the error.

由于这个问题,我每次对 API 进行更改时都必须重新连接会话.如果可以通过在蟾蜍或数据库级别进行任何配置来解决此问题,任何人都可以提供帮助.

Due to this issue, i am made to reconnect the session everytime i make a change to API. Can anyone help if this issue can be resolved by making any configurations in toad or database level.

推荐答案

我怀疑您只是在报告堆栈中的最后一个错误,如下所示:

I suspect you're only reporting the last error in a stack like this:

ORA-04068: existing state of packages has been discarded
ORA-04061: existing state of package body "schema.package" has been invalidated
ORA-04065: not executed, altered or dropped package body "schema.package"
ORA-06508: PL/SQL: could not find program unit being called: "schema.package"

如果是这样,那是因为您的包是有状态的:

If so, that's because your package is stateful:

一个包中的变量、常量和游标的值声明(在其规范或正文中)包含其 包状态.如果一个 PL/SQL 包至少声明了一个变量,常量,或游标,则包是有状态;否则,它是无状态.

The values of the variables, constants, and cursors that a package declares (in either its specification or body) comprise its package state. If a PL/SQL package declares at least one variable, constant, or cursor, then the package is stateful; otherwise, it is stateless.

重新编译时状态丢失:

如果实例化的有状态包的主体被重新编译(或者显式地,使用ALTER PACKAGE 语句",或隐式地),包中的子程序的下一次调用导致 Oracle 数据库丢弃现有的包状态并引发异常ORA-04068.

If the body of an instantiated, stateful package is recompiled (either explicitly, with the "ALTER PACKAGE Statement", or implicitly), the next invocation of a subprogram in the package causes Oracle Database to discard the existing package state and raise the exception ORA-04068.

PL/SQL 引发异常后,对包的引用导致Oracle 数据库重新实例化包,它重新初始化它...

After PL/SQL raises the exception, a reference to the package causes Oracle Database to re-instantiate the package, which re-initializes it...

如果您的包裹有状态,您就无法避免这种情况.我认为真正需要一个有状态的包是相当罕见的,所以你应该重新访问你在包中声明的任何东西,但在函数或过程之外,看看它是否真的需要在那个级别.不过,由于您使用的是 10g,这包括常量,而不仅仅是变量和游标.

You can't avoid this if your package has state. I think it's fairly rare to really need a package to be stateful though, so you should revisit anything you have declared in the package, but outside a function or procedure, to see if it's really needed at that level. Since you're on 10g though, that includes constants, not just variables and cursors.

但是引用文档中的最后一段意味着下次您在同一会话中引用该包时,您将不会收到错误并且它会正常工作(直到您再次重新编译).

But the last paragraph from the quoted documentation means that the next time you reference the package in the same session, you won't get the error and it will work as normal (until you recompile again).

相关文章