// Oracle error reference

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
Error message
existing state of packages string string string has been discarded

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

  1. Retry the call once in the application when this error is caught, then continue.

  2. 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);
  3. 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

More pl/sql errors

The code and message text are from the Oracle Database Error Help. Browse the full Oracle error list or search every database error.

// fewer errors, faster fixes

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.