Oracle
 SQL >> Datenbank >  >> RDS >> Oracle

ORA-06508 und zustandsbehaftete PL/SQL-Pakete verstehen

Der Fehler ORA-06508, den Sie sehen, ist meist nur das letzte Glied einer längeren Kette, die so aussieht:

ORA-04068: existing state of packages has been discarded ORA-04061: existing state of package body "schema.package" has been invalidated ORA-04065: not executed, altered or dropped package body "schema.package" ORA-06508: PL/SQL: could not find program unit being called: "schema.package" 

Die Grundursache ist, dass Ihr Paket zustandsbehaftet ist:

The values of the variables, constants, and cursors that a package declares (in either its specification or body) comprise its package state. If a PL/SQL package declares at least one variable, constant, or cursor, then the package is stateful; otherwise, it is stateless.

Kompilieren Sie ein solches Paket neu, wird dieser Zustand verworfen:

If the body of an instantiated, stateful package is recompiled (either explicitly, with the "ALTER PACKAGE Statement", or implicitly), the next invocation of a subprogram in the package causes Oracle Database to discard the existing package state and raise the exception ORA-04068. After PL/SQL raises the exception, a reference to the package causes Oracle Database to re-instantiate the package, which re-initializes it...

Solange das Paket Zustand hält, lässt sich das nicht vermeiden. In der Praxis ist ein echter Bedarf an Zustand recht selten, daher lohnt es sich, alles auf Paketebene – außerhalb einer Funktion oder Prozedur – Deklarierte zu überprüfen, ob es dort wirklich hingehört. Da Sie auf 10g sind, beachten Sie, dass dies Konstanten einschließt, nicht nur Variablen und Cursor.

Der Lichtblick: Beim nächsten Verweis Ihrer Sitzung auf das Paket wird es neu instanziiert und funktioniert normal – bis Sie es erneut neu kompilieren.