Skip to Main Content
  • Questions
  • Trigger - Not able to find the program unit being called

Breadcrumb

Question and Answer

Tom Kyte

Thanks for the question, Prabhu.

Asked: February 04, 2009 - 1:55 am UTC

Last updated: February 05, 2009 - 2:52 pm UTC

Version: 10.2.0

Viewed 10K+ times! This question is

You Asked

Hi ALL,

I have a custom trigger((After Insert/Update) on Oracle Apps standard table). This trigger inturn calls a custom package.

The problem is, some times this trigger completes with the following error message. This is not happening consitently.

"ORA-06508: PL/SQL: could not find program unit being called"

I am inserting the debug messages(from trigger) into a custom table. I could able to see the messages till we call the custom package, then it goes to trigger exception block with the above error message.

I am getting dependancy objects status from all_objects and inserting into the custom table just before call the package. All the object status are in "VALID". But still
I am getting the above error message.

Could any body throw some light to fix this issue ?

Regards,
Prabhu

and Tom said...

You didn't post the entire error stack, but I think I know what it is - ora-4068, existing state of packages discarded.

In short, your code maintains a state (has global variables).
Someone has recompiled your code - either explicitly or implicitly.
And they did this AFTER you established a state, thus they wiped it out.

we have to tell you "this happened"


in the following, we create a package that has a global variable.

We have a trigger that invokes this package.

We run it twice - no worries, it works.

In another session, we cause the code to recompile - note that it is always valid, it never is invalid!

When we try to run the trigger again - error. We have to tell you that your package was wiped out, your code must depend on these globals (or you wouldn't use them because we know that global variables are in general evil evil things and we'd never use them unless there was no other way!)

Later, when we try the insert again, it works (because we told you - we are off the hook now, caveat emptor)



ops$tkyte%ORA10GR2> create or replace package stateful_pkg
  2  as
  3          procedure p;
  4  end;
  5  /

Package created.

ops$tkyte%ORA10GR2> create or replace package body stateful_pkg
  2  as
  3          g_another_global_variable number := 0;
  4
  5          procedure p
  6          is
  7          begin
  8                  g_another_global_variable := g_another_global_variable+2;
  9          end;
 10  end;
 11  /

Package body created.

ops$tkyte%ORA10GR2>
ops$tkyte%ORA10GR2> create table t ( x int );

Table created.

ops$tkyte%ORA10GR2>
ops$tkyte%ORA10GR2> create or replace trigger t_trigger
  2  before insert on t
  3  for each row
  4  begin
  5          stateful_pkg.p;
  6  end;
  7  /

Trigger created.

ops$tkyte%ORA10GR2>
ops$tkyte%ORA10GR2> insert into t values ( 1 );

1 row created.

ops$tkyte%ORA10GR2> insert into t values ( 2 );

1 row created.

ops$tkyte%ORA10GR2>
ops$tkyte%ORA10GR2> set echo off
in another session - execute this:
create or replace package stateful_pkg
as
-- I''ve changed something...
type array is table of number index by binary_integer;
g_data array;
procedure p;
end;
/

ops$tkyte%ORA10GR2> insert into t values ( 3 );
insert into t values ( 3 )
            *
ERROR at line 1:
ORA-04068: existing state of packages has been discarded
ORA-04061: existing state of package "OPS$TKYTE.STATEFUL_PKG" has been
invalidated
ORA-04065: not executed, altered or dropped package "OPS$TKYTE.STATEFUL_PKG"
ORA-06508: PL/SQL: could not find program unit being called:
"OPS$TKYTE.STATEFUL_PKG"
ORA-06512: at "OPS$TKYTE.T_TRIGGER", line 2
ORA-04088: error during execution of trigger 'OPS$TKYTE.T_TRIGGER'


ops$tkyte%ORA10GR2> insert into t values ( 3 );

1 row created.

Rating

  (3 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Its just one guy

karthick pattabiraman, February 05, 2009 - 12:14 am UTC

>>Hi ALL,

There is NO ALL here. Its just Tom ;)

Trigger - Not able to find the program unit being called

A reader, February 05, 2009 - 12:19 am UTC

Hi Tom,

Thanks for your quick response. I will check this and let you know..

Regards,
Prabhu

What counts as package state

Georg, February 05, 2009 - 2:39 pm UTC

I once found that even constant variables in a package spec count as package state. But what about referenced packages.
Can i somehow list my package state?
Tom Kyte
February 05, 2009 - 2:52 pm UTC

it is all global variables.

There is no way to "list" the state, you either have globals or not.

More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library