package global variable issue

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.

你可能感兴趣的:(sql)