ORA-04068: existing state of packages has been discarded
A package this session had already used was recompiled or changed, so its package-level variables were reset. The next call usually works.
- Error code
ORA-04068- Category
- PL/SQL
What it means
Package-level variables keep their values for the life of a session. When a package (or something it depends on) is recompiled, sessions that had used it lose that state, and their next call raises ORA-04068, often followed by ORA-04061 and ORA-04065 or ORA-06508. Calling again in the same session normally succeeds, with the state re-initialized.
Common causes
- Deploying a new version of a package while application sessions are connected.
- A change to a table, type or other object the package depends on, which invalidated it.
- Packages with global variables (stateful packages) used from connection pools.
How to fix it
-
Retry the call once in the application when this error is caught, then continue.
-
Recompile invalid objects after deployments.
SELECT object_name, object_type FROM user_objects WHERE status = 'INVALID'; EXEC DBMS_UTILITY.COMPILE_SCHEMA(schema => USER, compile_all => FALSE);
-
Keep packages stateless where you can (no package-level variables), or mark them
PRAGMA SERIALLY_REUSABLE, so recompiling them doesn't discard session state.
Related errors
ORA-06508PL/SQL: could not find program unit being calledORA-04021timeout waiting to lock objectORA-06512at line (PL/SQL error stack)
More pl/sql errors
ORA-01403no data foundORA-01422exact fetch returns more than requested rowsORA-06502PL/SQL: numeric or value errorORA-06550PL/SQL compilation error at line, columnORA-06503PL/SQL: function returned without valueORA-04091table is mutating, trigger may not see itORA-04088error during execution of trigger
The code and message text are from the Oracle Database Error Help. Browse the full Oracle error list or search every database error.
Work on Oracle in SQLly
A native SQL client for macOS, Windows and Linux with schema-aware IntelliSense, guardrails for risky statements and clear error messages, for Oracle and the other databases you use.