0

I have a trigger somewhat like this (Sorry can't display actual sql because of company rules and this is from a different machine):

create or replace trigger TR_TABLE_X_AU
after update
  on TABLE_X
for each row

declare
  cursor cursor_select_fk is
    select FK_FOR_ANOTHER_TABLE
      from TABLE_Y Y, TABLE_Z Z
     where :NEW.JOINING_COL = Y.JOINING_COL
       and Y.JOINING_COL = Z.JOINING_COL
       and :NEW.FILTER_CONDITION_1 = Y.FILTER_CONDITION_1
       and :NEW.FILTER_CONDITION_2 = Y.FILTER_CONDITION_2
       and :NEW.SOME_DATE_COL = (select max(SOME_DATE_COL)
                                   from TABLE_X
                                  where FILTER_CONDITION_1 = :NEW.FILTER_CONDITION_1 
                                    and FILTER_CONDITION_2 = :NEW.FILTER_CONDITION_2)
begin
  for rec in cursor_select_fk loop
    PCK_SOME_PACKAGE.SOME_PROC(rec.FK_FOR_ANOTHER_TABLE);
  end loop;
end TR_TABLE_X_AU;

We resulted to triggers since it is an enhancement. The nested query selecting the max date seems to be the cause of the problem. Changing it to sysdate results to no exceptions. Any idea on how I can get the max date during the execution of the trigger for TABLE_X? Thanks!

EDIT: Also, it seems similar functions such as count,sum,etc... produces the same error. Anyone knows a workaround to this?

4

1 回答 1

4

A mutating table is a table that is being modified by an UPDATE, DELETE, or INSERT statement, or a table that might be updated by the effects of a DELETE CASCADE constraint.

The session that issued the triggering statement cannot query or modify a mutating table. This restriction prevents a trigger from seeing an inconsistent set of data.

Trigger Restrictions on Mutating Tables

Which means, you cannot issue max(some_date_col) on your TABLE_X in a row-level trigger.

Compound trigger could be a possible workaround.

于 2013-05-10T10:47:21.530 回答