ORA-04061: existing state of has been invalidated
.session 1:
Session_1>create package pck is
2 a number;
3 procedure print_a;
4 end pck;
5 /
Package created.
Session_1>create or replace package body pck is
2 procedure print_a is
3 begin
4 dbms_output.put_line(a);
5 end print_a;
6 begin
7 a:= 9;
8 end;
9 /
Package body created.
Session_1>exec pck.print_a;
9
PL/SQL procedure successfully completed.
session 2:
Session_2> exec pck.print_a;
9
PL/SQL procedure successfully completed.
back to session 1, compiling the package header:
Session_1>alter package pck compile;
Package altered.
getting the error in session 2:
Session_2> exec pck.print_a;
BEGIN pck.print_a; END;
*
ERROR at line 1:
ORA-04068: existing state of packages has been discarded
ORA-04061: existing state of package body "HR_APP.PCK" has been invalidated
ORA-04065: not executed, altered or dropped package body "HR_APP.PCK"
ORA-06508: PL/SQL: could not find program unit being called: "HR_APP.PCK"
ORA-06512: at line 1
solution:
a. don't compile at the production environment, or at least not the parts of the package that contain the global variable
b. long term solution - remove global variable from package.
Amiel.
.session 1:
Session_1>create package pck is
2 a number;
3 procedure print_a;
4 end pck;
5 /
Package created.
Session_1>create or replace package body pck is
2 procedure print_a is
3 begin
4 dbms_output.put_line(a);
5 end print_a;
6 begin
7 a:= 9;
8 end;
9 /
Package body created.
Session_1>exec pck.print_a;
9
PL/SQL procedure successfully completed.
session 2:
Session_2> exec pck.print_a;
9
PL/SQL procedure successfully completed.
back to session 1, compiling the package header:
Session_1>alter package pck compile;
Package altered.
getting the error in session 2:
Session_2> exec pck.print_a;
BEGIN pck.print_a; END;
*
ERROR at line 1:
ORA-04068: existing state of packages has been discarded
ORA-04061: existing state of package body "HR_APP.PCK" has been invalidated
ORA-04065: not executed, altered or dropped package body "HR_APP.PCK"
ORA-06508: PL/SQL: could not find program unit being called: "HR_APP.PCK"
ORA-06512: at line 1
solution:
a. don't compile at the production environment, or at least not the parts of the package that contain the global variable
b. long term solution - remove global variable from package.
Amiel.
本文探讨了在Oracle数据库中因包头编译导致的ORA-04061等错误的原因及解决方法。通过一个具体的例子展示了当一个会话中修改了包头后,另一个正在使用该包体的会话会出现的状态无效错误。文章提供了短期和长期解决方案,包括避免在生产环境中编译或移除包中的全局变量。
929

被折叠的 条评论
为什么被折叠?



