I have an Oracle 10G installation (Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 – Prod), and a java web app that calls stored procedures and functions in oracle via a JDBC connection. The SP’s and functions are part of a package. The first time a SP or a function is called, after the package is successfully compiled, I get these errors:
(I replaced our schema name and package name with “#schema-name#.#package-name#”)
ORA-04068: existing state of packages has been discarded
ORA-04061: existing state of package body "#schema-name#.#package-name#" has been invalidated
ORA-04065: not executed, altered or dropped package body "#schema-name#.#package-name#"
ORA-06508: PL/SQL: could not find program unit being called: "#schema-name#.#package-name#"
ORA-06512: at "#schema-name#.#package-name#", line 5393
ORA-06512: at line 1
The very next time it is called, everything runs the way that it should. Any ideas on why and how to keep this from happening?
This is normal behavior for packages that have state, i.e. they have body variables. When the package is compiled, the existing state has to be discared and all session that have used the package before receive the ORA-04068 error (except the one that compiled the package).
As you have a web application, I assume it uses a connection pool that keeps the session alive. So they will all be affected if they have used the package before.
One workaround is to call
DBMS_SESSION.RESET_PACKAGE, which discards the state of all packages of the current session. Another one is to check whether you can get rid of the session state, which is somewhat problematic in combination with a connection pool.