我正在使用 oracle 10g 和 toad 11.5。我正在尝试从匿名 block 调用 api。
如果我在添加 dbms_output.put_line
后重新编译 api然后尝试执行匿名 block ,它显示错误为:
"ORA-06508: PL/SQL: could not find program unit being called".
但是,如果我结束当前 session 并打开一个新 session ,那么匿名 block 将在没有错误的情况下执行。由于这个问题,每次我对 API 进行更改时,我都会重新连接 session 。
如果可以通过在 toad 或数据库级别进行任何配置来解决此问题,任何人都可以提供帮助。
最佳答案
我怀疑你只报告堆栈中的最后一个错误,如下所示:
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"
如果是这样,那是因为 your package is stateful :
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.
当您重新编译时,状态会丢失:
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.
After PL/SQL raises the exception, a reference to the package causes Oracle Database to re-instantiate the package, which re-initializes it...
如果你的包有状态,你就无法避免这种情况。我认为真正需要有状态的包是相当罕见的,所以你应该重新访问你在包中声明的任何东西,但在函数或过程之外,看看它是否真的需要在那个级别。由于您使用的是 10g,因此其中包括常量,而不仅仅是变量和游标。
但是引用文档的最后一段意味着下次您在同一 session 中引用该包时,您将不会收到错误并且它将正常工作(直到您再次重新编译)。
关于oracle - ORA-06508 : PL/SQL: could not find program unit being called,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19376440/