How to Fix ORA-06508: PL/SQL: Could Not Find Program Unit Being Called in Oracle

Read the error that comes with ORA-06508, such as ORA-04067, and restore or recompile the program unit that could not be run.

ORA-06508 is raised at run time when PL/SQL code calls a program unit that cannot be executed: it was dropped, it has no body, or it was replaced while the session was using an older version of it. The caller itself compiled fine, which is why the error comes at run time. ORA-06508 usually follows a more specific error, such as ORA-04067 or ORA-04068, that tells which case it is.

Reproduce the Error

A job procedure calls a package, and the package body is dropped:

Example:

create or replace package demo_rates_pkg is
  procedure refresh;
end;
/
create or replace package body demo_rates_pkg is
  procedure refresh is begin null; end;
end;
/
create or replace procedure demo_nightly_job is
begin
  demo_rates_pkg.refresh;
end;
/
drop package body demo_rates_pkg;           -- the spec stays, the code is gone
exec demo_nightly_job

Output:

Package DEMO_RATES_PKG compiled

Package Body DEMO_RATES_PKG compiled

Procedure DEMO_NIGHTLY_JOB compiled

Package body DEMO_RATES_PKG dropped.

BEGIN demo_nightly_job; END;
*
ERROR at line 1:
ORA-04067: not executed, package body "NIMBUS.DEMO_RATES_PKG" does not exist
ORA-06508: PL/SQL: could not find program unit being called: "NIMBUS.DEMO_RATES_PKG"
ORA-06512: at "NIMBUS.DEMO_NIGHTLY_JOB", line 3
ORA-06512: at line 1

ORA-04067 gives the cause: the package body does not exist. ORA-06512 shows the call came from line 3 of DEMO_NIGHTLY_JOB.

Fix: Restore the Missing Unit

Example:

select object_name, object_type, status from user_objects
where  object_name in ('DEMO_RATES_PKG', 'DEMO_NIGHTLY_JOB') order by 1, 2;
create or replace package body demo_rates_pkg is
  procedure refresh is begin null; end;
end;
/
exec demo_nightly_job

Output:

OBJECT_NAME         OBJECT_TYPE    STATUS
___________________ ______________ _________
DEMO_NIGHTLY_JOB    PROCEDURE      VALID
DEMO_RATES_PKG      PACKAGE        VALID

Package Body DEMO_RATES_PKG compiled

PL/SQL procedure successfully completed.

Both objects show VALID even while the body is missing, because the caller depends on the package specification only. After the body is created again, the call works.

Other Causes

  • The package was recompiled while the session held its state: the stack starts with ORA-04068, and the next call works.
  • The called unit is invalid and does not compile; check USER_ERRORS for it.

Related Guides

Conclusion

ORA-06508 means a called program unit could not be run. Read the error above it in the stack, then restore the missing body, fix the invalid unit, or simply call again after a package recompile.

Vinish Kapoor
Vinish Kapoor

An Oracle ACE, author of four books on Oracle APEX, SQL and PL/SQL, and Oracle Forms, and a software developer building Oracle database applications since 2001.

guest

0 Comments
Oldest
Newest Most Voted