*Something* is making that package go invalid. Let's start with this:
SQL> create or replace
2 package PKG is
3 procedure P;
4 end;
5 /
Package created.
SQL>
SQL> create or replace
2 package body PKG is
3 global_var int;
4 procedure P is
5 x emp%rowtype;
6 begin
7 select * into x from emp where rownum = 1;
8 end;
9 end;
10 /
Package body created.
SQL>
SQL> select object_type, status
2 from user_objects
3 where object_name = 'PKG';
OBJECT_TYPE STATUS
----------------------- -------
PACKAGE VALID
PACKAGE BODY VALID
2 rows selected.
SQL>
SQL> alter table emp drop column deptno;
Table altered.
SQL>
SQL> select object_type, status
2 from user_objects
3 where object_name = 'PKG';
OBJECT_TYPE STATUS
----------------------- -------
PACKAGE VALID
PACKAGE BODY INVALID
2 rows selected.
SQL>
SQL> exec pkg.p;
PL/SQL procedure successfully completed.
SQL>
SQL> select object_type, status
2 from user_objects
3 where object_name = 'PKG';
OBJECT_TYPE STATUS
----------------------- -------
PACKAGE VALID
PACKAGE BODY VALID
2 rows selected.
You can see that DDL on EMP (which PKG depends on) made it invalid. The next time we ran it, we automatically tried to recompile it, found that it was ok, and hence we ran it. But the key thing here is that we recompiled it (either automatically or manually).
From another session's perspective, you *recompiled* that package. For all it knows, you might have loaded a totally new version of the code, one that might not even *have* any global variables in it. It could have been anything - that is why we have the discard the state, because it doesn't know what has been going on the other session.
An easy way to handle this on a more permanent basis, is move the global variables to their own package. Then they are insulated from changes.
In session 2 I did:
--
-- after I first created the package
--
SQL> exec pkg.p
PL/SQL procedure successfully completed.
--
-- after the drop column *and* after session 1 had recompiled it
--
SQL> exec pkg.p
BEGIN pkg.p; END;
*
ERROR at line 1:
ORA-04068: existing state of packages has been discarded
ORA-04061: existing state of package body "MCDONAC.PKG" has been invalidated
ORA-04065: not executed, altered or dropped package body "MCDONAC.PKG"
ORA-06508: PL/SQL: could not find program unit being called: "MCDONAC.PKG"
ORA-06512: at line 1
The solution I prefer (if you *must* have globals) is to put the globals in a separate package. eg
SQL> create or replace
2 package PKG_G is
3 global_var int;
4 end;
5 /
Package created.
would be a "partner" package to PKG. Then when you do things to PKG, PKG_G will remain unimpacted.