oracle ORA-06508: PL/SQL: 找不到被调用的程序单元
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19376440/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ORA-06508: PL/SQL: could not find program unit being called
提问by battech
I am using oracle 10g and toad 11.5. I am trying to call an api from an anonymous block.
我正在使用 oracle 10g 和 toad 11.5。我正在尝试从匿名块调用 api。
If i recompile the api after adding dbms_output.put_line
and then try to execute the anonymous block ,it shows error as
如果我在添加后重新编译 apidbms_output.put_line
然后尝试执行匿名块,它会显示错误为
"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.
但是,如果我结束当前会话并打开一个新会话,则匿名块将执行而不会出现错误。
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.
由于这个问题,每次我对 API 进行更改时,我都必须重新连接会话。如果可以通过在蟾蜍或数据库级别进行任何配置来解决此问题,任何人都可以提供帮助。
回答by Alex Poole
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:
如果是这样,那是因为您的包是有状态的:
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.
包声明的变量、常量和游标的值(在其规范或主体中)构成其包状态。如果 PL/SQL 包至少声明了一个变量、常量或游标,则该包是有状态的;否则,它是无状态的。
When you recompile the state is lost:
重新编译时,状态丢失:
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...
如果实例化的有状态包的主体被重新编译(显式,使用“ALTER PACKAGE 语句”,或隐式),包中子程序的下一次调用将导致 Oracle 数据库丢弃现有包状态并引发异常 ORA -04068。
在 PL/SQL 引发异常后,对该包的引用会导致 Oracle 数据库重新实例化该包,从而重新初始化它...
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.
如果您的包裹有状态,您将无法避免这种情况。我认为真正需要一个有状态的包是相当罕见的,所以你应该重新访问你在包中声明的任何东西,但在函数或过程之外,看看它是否真的需要在那个级别。但是,由于您使用的是 10g,因此它包括常量,而不仅仅是变量和游标。
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).
但是引用文档的最后一段意味着下次您在同一会话中引用该包时,您将不会收到错误并且它会正常工作(直到您再次重新编译)。
回答by mkb
seems like opening a new session is the key.
似乎打开一个新会话是关键。
see thisanswer.
看到这个答案。
and here is an awesome explanation about this error
回答by friendmanish
Based on previous answers. I resolved my issue by removing global variable at package level to procedure, since there was no impact in my case.
根据之前的回答。我通过在程序包级别删除全局变量来解决我的问题,因为对我的情况没有影响。
Original scriptwas
原始脚本是
create or replace PACKAGE BODY APPLICATION_VALIDATION AS
V_ERROR_NAME varchar2(200) := '';
PROCEDURE APP_ERROR_X47_VALIDATION ( PROCESS_ID IN VARCHAR2 ) AS BEGIN
------ rules for validation... END APP_ERROR_X47_VALIDATION ;
/* Some more code
*/
END APPLICATION_VALIDATION; /
Rewritten the same without global variable V_ERROR_NAME
and moved to procedure under package level as
在没有全局变量的情况下重写相同V_ERROR_NAME
并移至包级别下的过程作为
Modified Code
修改代码
create or replace PACKAGE BODY APPLICATION_VALIDATION AS
PROCEDURE APP_ERROR_X47_VALIDATION ( PROCESS_ID IN VARCHAR2 ) AS
**V_ERROR_NAME varchar2(200) := '';**
BEGIN
------ rules for validation... END APP_ERROR_X47_VALIDATION ;
/* Some more code
*/
END APPLICATION_VALIDATION; /
回答by Brian Sebastian
I recompiled the package specification, even though the change was only in the package body. This resolved my issue
我重新编译了包规范,即使更改仅在包体中。这解决了我的问题