SQL Oracle ORA-04068 中的常见错误:包的现有状态已被丢弃
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1761595/
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
Frequent error in Oracle ORA-04068: existing state of packages has been discarded
提问by jonasespelita
We're getting this error once a day on a script that runs every two hours, but at different times of the day.
我们每天都会在每两个小时运行一次的脚本上收到此错误,但在一天中的不同时间。
ERROR at line 1:
ORA-04068: existing state of packages has been discarded
ORA-04061: existing state of package body "PACKAGE.NAME" has been
invalidated
ORA-06508: PL/SQL: could not find program unit being called:
"PACKAGE.NAME"
ORA-06512: at line 1
Could someone list what conditions can cause this error so that we could investigate?
有人可以列出导致此错误的条件,以便我们进行调查吗?
Thanks.
谢谢。
UPDATE:
Would executing 'ALTER SESSION CLOSE DATABASE LINK DBLINK'
invalidate a state of the package?
更新:执行'ALTER SESSION CLOSE DATABASE LINK DBLINK'
会使包的状态无效吗?
回答by Christian13467
The package has public or private variables. (Right?) This variables form the state a the package. If you compile the package in 3rd session. The next access to this package will throw the ORA-04068.
该包具有公共或私有变量。(对吗?)这个变量形成了包的状态。如果您在第 3 个会话中编译该包。下次访问这个包会抛出 ORA-04068。
The build timestamp of a package must be older than the package session state.
包的构建时间戳必须早于包会话状态。
If the package state is not needed for script running, the call DBMS_SESSION.RESET_PACKAGE
at the beginning of your script. This cleans all package states of your session.
如果脚本运行不需要包状态,则DBMS_SESSION.RESET_PACKAGE
在脚本开头调用。这会清除会话的所有包状态。
回答by jonasespelita
This one liner actually solved everything:
这个班轮实际上解决了一切:
PRAGMA SERIALLY_REUSABLE;
Be sure that your global variables are stateless to avoid any issues.
确保您的全局变量是无状态的,以避免出现任何问题。
回答by Guru
You may also check dba_dependencies
or user_dependencies
.
您也可以检查dba_dependencies
或user_dependencies
。
select *
from dba_dependencies
where name = 'YOUR_PACKAGE'
and type = 'PACKAGE' --- or 'PACKAGE_BODY'
and owner = USER --- or USERNAME
This will give you the objects your package is dependent on. Check whats happening in there.
这将为您提供包所依赖的对象。检查那里发生了什么。
回答by VRK
We have had this issues for couple of times and for time being, we were compiling schema to resolve this issue temporarily. Over couple of days we were searching for the permanent resolution.
我们已经遇到过几次这个问题,暂时,我们正在编译架构来暂时解决这个问题。几天来,我们一直在寻找永久解决方案。
We found below query that showed timestamp difference in our synonym. we recompiled synonym and It worked !!! It's been almost a week and so far we have no issues. Here is the query that helped in our case.
我们发现以下查询显示我们的同义词中的时间戳差异。我们重新编译了同义词,它起作用了!!!已经快一个星期了,到目前为止我们没有任何问题。这是对我们的案例有帮助的查询。
**
**
select do.obj# d_obj,do.name d_name, do.type# d_type, po.obj# p_obj,po.name p_name,
to_char(p_timestamp,'DD-MON-YYYY HH24:MI:SS') "P_Timestamp",
to_char(po.stime ,'DD-MON-YYYY HH24:MI:SS') "STIME",
decode(sign(po.stime-p_timestamp),0,'SAME','*DIFFER*') X
from sys.obj$ do, sys.dependency$ d, sys.obj$ po
where P_OBJ#=po.obj#(+) and D_OBJ#=do.obj#
and do.status=1 /*dependent is valid*/
and po.status=1 /*parent is valid*/
and po.stime!=p_timestamp /*parent timestamp not match*/
order by 2,1;
**
**
I hope this helps someone who may be having this issue.
我希望这可以帮助可能遇到此问题的人。
回答by borjab
It seems that you are making changes to your objects that make other objects invalid. Droping an index for example can put into an invalid state all the packages that dependes on that table. It can have a cascade efect. If the package is invalid, the funciton that depends on the package and the view that uses the function can become invalid. Try to recompile all the objects after every DDL query.
您似乎正在对您的对象进行更改,从而使其他对象无效。例如,删除索引会使依赖于该表的所有包都处于无效状态。它可以产生级联效应。如果包无效,则依赖于包的函数和使用该函数的视图可能会失效。尝试在每次 DDL 查询后重新编译所有对象。