Is there any way in Oracle to determine whether a package has state or is stateless? I'm not aware of any view in the data dictionary that contains that information.
The "ORA-04068: existing state of packages string has been discarded" error is rather annoying. It can be eliminated by removing package variables from the package. 11g introduced the feature that a package with variables that are all compile-time constants will be treated as stateless.
I could have two sessions and compile the package in one and call it in the other and see if it throws an exception, but that requires calling a procedure in the package, which may not be desirable.
It sounds like what you want is to be able to list all packages that may potentially have state.
What you're looking for is just packages that have any global variables or constants. For a single package, this is quite simple by inspection. To look across all packages in a schema, however, you could use PL/Scope:
First, log in as the schema owner, turn on PL/Scope in your session:
Then, recompile all your package bodies.
Then, run this query to find all the variables and constants declared at the package level:
I'd suggest the resulting list of packages will be your target.
If you're on 11gR2, constants no longer cause this problem, so you'd use this query instead: