Invalid packages in Oracle are stored PL/SQL units whose compiled code no longer matches what the database expects—usually because a dependency changed or a compile failed. To check for them, query the data dictionary views DBA_OBJECTS or ALL_OBJECTS filtered on STATUS = 'INVALID' and OBJECT_TYPE = 'PACKAGE', then use DBMS_UTILITY.COMPILE_SCHEMA or ALTER PACKAGE ... COMPILE to recompile and confirm the status flips to VALID. The key condition: USER_OBJECTS only shows objects you own, so use ALL_OBJECTS or DBA_OBJECTS when you need cross-schema visibility.
A package can also show VALID at the package level while one of its spec's referenced objects is stale, so the basic query is a starting point, not the whole answer. What follows walks through the mechanics, the diagnosis order, the recompile options (including EDITIONABLE, PLSQL_OPTIMIZE_LEVEL, and RESOLVE ANY semantics), and the cases where an invalid package is a symptom rather than the disease.
What "Invalid" Actually Means for an Oracle Package
Oracle keeps a status flag on every stored object in the data dictionary. For PL/SQL packages, STATUS is VALID or INVALID, and there's a separate timestamp pair: LAST_DDL_TIME and TIMESTAMP. When a package body compiles, Oracle records the dependencies it resolved—tables, views, other packages, types, sequences. If one of those dependencies changes in a way the compiler can't reconcile, the dependent package is marked INVALID rather than being recompiled immediately. That lazy invalidation is deliberate: it keeps DDL fast and pushes the cost to first use.
The distinction between the package specification and the package body matters here. The spec is the public interface; the body is the implementation. Changing a table that only the body references invalidates the body but leaves the spec VALID. Changing a type used in the spec's procedure signatures can invalidate the spec itself. Queries that aggregate on OBJECT_TYPE = 'PACKAGE' miss the body's status, which is recorded as PACKAGE BODY. So the first practical lesson: check both object types, because they carry independent status values.
A third nuance: an object can be INVALID yet still work if Oracle can resolve it at runtime through a mechanism like editioning or a deferred dependency. "Invalid" is a compile-time state, not a guarantee of runtime failure. Conversely, VALID does not prove the code runs—a package can be valid and still throw ORA-06502 or ORA-04063 on execution. The status flag answers "does the stored code match its recorded dependencies," not "is this code correct."
Prerequisites Before You Start Querying
You need read access to the relevant data dictionary view. A normal user can query USER_OBJECTS for their own schema. ALL_OBJECTS requires no special grant beyond the standard SELECT_CATALOG_ROLE-style access most accounts have in practice, but DBA_OBJECTS requires SELECT on that view, typically via SELECT_CATALOG_ROLE or a direct grant. If you're troubleshooting a specific application schema and don't have DBA_OBJECTS, ask for SELECT on ALL_OBJECTS and filter by OWNER.
Confirm which database and schema you're actually connected to before drawing conclusions. A common error is querying USER_OBJECTS while logged in as SYS or SYSTEM and concluding "no invalid packages exist" when the application schema is APP_OWNER. Run SELECT SYS_CONTEXT('USERENV','CURRENT_SCHEMA') FROM dual; to see the default schema, and SELECT name FROM v$database; to confirm the instance. Also note the Oracle version—V$VERSION returns the banner—because behavior around editioning and RESOLVE ANY has shifted across 11g, 12c, and 19c.
One more prerequisite: know whether you're looking at a primary, a standby, or a clone. Data dictionary content on a physical standby reflects the primary's DDL through redo, so statuses should match, but a snapshot standby can carry its own dictionary state. That detail prevents a lot of confused post-incident analysis.
The Core Query: Listing Invalid Packages
The direct check filters the object views on status and type. For the current schema:
For all schemas you can see:
And with DBA_OBJECTS you get the full picture:
The exclusion list matters. Oracle's own schemas routinely contain invalid objects after upgrades and patch application, and they're frequently harmless because they're not invoked until needed. Filtering them keeps the output actionable. If your application schema shows zero rows here, that's your baseline: no invalid packages at this moment.
Two refinements worth knowing. First, last_ddl_time tells you when the object was last modified, not when it became invalid—those can differ if a dependency changed without a DDL on the package itself. Second, if you want to catch packages that are invalid and haven't been touched recently, add a date filter, e.g. AND last_ddl_time < SYSDATE - 7, to surface the stale ones.
Checking a Single Package and Its Body Separately
When you already suspect a package, query it directly rather than scanning everything:
You can get two rows: MY_PKG as PACKAGE and MY_PKG as PACKAGE BODY. They can disagree. A VALID spec with an INVALID body is the most common situation and usually resolves on first execution or with an explicit body compile. An INVALID spec is more serious because the public interface itself failed to compile; dependent objects that reference it may be invalid too.
To see why the package is invalid, you need the compilation errors, which live in USER_ERRORS, ALL_ERRORS, or DBA_ERRORS:
If you see no rows in ALL_ERRORS but the object is INVALID, that's informative. It typically means the invalidation came from a dependency change (a table was altered, a view was dropped and recreated) rather than a failed compile with errors. Oracle didn't recompile, so it recorded no errors. The fix is a recompile, not a code change.
Reading the Dependency Chain
To understand why a package went invalid, ask what it depends on:
This lists tables, views, other packages, types, and sequences the package resolves at compile time. Cross-reference that list against recently changed objects—check last_ddl_time on the referenced items—to find the culprit. If a referenced view was recreated, for example, the package body may be invalid because the view's underlying column list changed.
There's a subtlety with ALL_DEPENDENCIES: it shows the dependencies recorded at last compile. If a dependency was dropped entirely, the package may be invalid but the dropped object won't appear in this view. For that case, DBA_DEPENDENCIES or a runtime attempt that produces ORA-04063: package body has errors or ORA-00942: table or view does not exist tells you the missing piece. Also consider ALL_IDENTIFIERS for fine-grained PL/SQL dependency information, which records individual PL/SQL identifiers the package references—useful for pinpointing which procedure signature change broke a caller.
Compiling to Resolve Invalid Status
Once you know what's invalid, the standard remedy is a recompile. For a single package:
COMPILE on the spec recompiles the spec and, by default in recent releases, the body as well if the spec is valid; COMPILE BODY targets the implementation. In practice many DBAs run both to be explicit. Note the session's current schema matters for unqualified names, and the ALTER PACKAGE privilege on another user's package requires the appropriate object privilege or ALTER ANY PROCEDURE.
For a whole schema, prefer the PL/SQL API because it gives you control over parallelism and error collection:
reuse_settings => TRUE keeps the schema's existing PLSQL_OPTIMIZE_LEVEL, PLSQL_CODE_TYPE, PLSQL_WARNINGS, and similar settings rather than resetting to defaults—important when your packages were compiled with non-default optimization levels. compile_all => FALSE compiles only invalid objects, which is faster; compile_all => TRUE forces every object through the compiler and is used after major upgrades.
The 12c+ UTL_RECOMP package offers a parallel, more robust alternative:
UTL_RECOMP requires EXECUTE on the package and typically runs as SYS or a highly privileged user; it's the recommended tool for post-patch recompilation because it accounts for invalid objects that appear during the recompile and retries them in dependency order.
Verifying That the Fix Worked
Recompile success doesn't equal validity. After compiling, re-run the status query:
Expect both rows to show VALID and last_ddl_time to have advanced. If the spec is VALID and the body is still INVALID, check ALL_ERRORS again—the recompile likely failed with a real error. A package that flips back to INVALID after a compile is usually the victim of an invalid dependency that itself needs fixing first; recompiling a package whose dependency is broken just reproduces the failure.
There's a catch with "valid" as a success metric: runtime validation happens separately. A package can be VALID and still fail at execution due to privileges, a missing synonym, edition resolution, or data-dependent logic. So the real check is to execute a representative procedure from the package—ideally from a session using the same schema and edition as the application—and confirm it returns rather than raising ORA-04063 or ORA-06508. In test environments, a smoke test of the package's most-used entry points catches problems the dictionary can't.
Recompile Failures and Reversible Troubleshooting
When the recompile doesn't reach VALID, work the causes from least invasive to most. First, read ALL_ERRORS for the exact line and message; ORA-00904: invalid identifier points at a schema mismatch or renamed column, ORA-06550 at a PL/SQL parse issue, and ORA-04063 at a broken dependency. Second, verify the dependency objects themselves are valid—a chain of invalid objects should be fixed bottom-up, starting with the base tables and views and ending with packages. Third, confirm the compiling user has the object privileges the package requires; compile-time privileges differ from runtime, and a package referencing another schema's table needs the grant at compile time unless PLSQL_OPTIMIZE_LEVEL and invoker-rights settings alter the rules.
If a package compiled previously with particular settings, check ALL_PLSQL_OBJECT_SETTINGS for its PLSQL_OPTIMIZE_LEVEL, PLSQL_CODE_TYPE, PLSQL_DEBUG, and PLSQL_WARNINGS values, and pass matching settings to the recompile. A package compiled as interpreted with warnings enabled can fail or behave differently when recompiled as native. As an escalation before calling in help, use DBMS_UTILITY.VALIDATE or the ALTER ... COMPILE with your session's PLSQL_CCFLAGS set, and capture the full error stack.
The specific stop condition: if the errors reference internal Oracle components, if recompilation is corrupting dictionary state, or if the invalid package belongs to an Oracle-supplied component (SYS, XDB, MDSYS, and so on), stop and engage Oracle Support or a senior DBA rather than repeatedly forcing compiles. Oracle's own invalid objects are frequently expected and should not be manually recompiled without guidance.
A Repeatable Monitoring Routine
For ongoing hygiene rather than a one-time fix, schedule a check. A lightweight daily query against DBA_OBJECTS filtered to application schemas, inserted into a monitoring table with the current timestamp, gives you a trend line:
Alert when the count rises or stays elevated for more than a day. Oracle's own DBA_OBJECTS invalid count is a documented, supported health indicator, but treat it as a signal rather than a guarantee: a handful of invalid synonym-based objects can persist harmlessly, while a single invalid package in a critical schema is worth verifying. Also run the check after every application deployment, every database patch, and every table structure change—those are the three events most likely to produce invalid packages. Documenting the baseline count for each schema turns an ambiguous "is this normal?" into a quick comparison.
FAQ
Does a valid package ever fail at runtime? Yes. STATUS records compile-time dependency resolution, not correctness or privileges. Runtime failures like ORA-04063, ORA-06508, or data exceptions can occur on a valid package, especially after an edition or privilege change.
Why do I see invalid objects in Oracle's own schemas? Oracle ships some objects invalid and resolves them on first use; upgrades and patches also routinely leave invalid objects in system schemas until a post-patch recompile. Don't recompile them manually without vendor guidance.
What's the difference between ALTER PACKAGE ... COMPILE and DBMS_UTILITY.COMPILE_SCHEMA? The former targets one package; the latter sweeps a schema, optionally only invalid objects, with control over whether existing compile settings are kept. UTL_RECOMP_DIRECT or UTL_RECOMP is better for post-upgrade bulk recompilation.
Can I fix an invalid package while sessions are using it? A recompile is generally safe, but sessions may briefly see different behavior or errors during the change. In production, recompile during a low-activity window and verify with a smoke test.