×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Mutating table with a BEFORE UPDATE statement what is the workaround?

Mutating table with a BEFORE UPDATE statement what is the workaround?

Mutating table with a BEFORE UPDATE statement what is the workaround?

(OP)
Hi, you can call me XANADOO or Phil :)

I have a mutating table error that occurs when I try to insert into a table which has a before insert trigger on it. I found a workaround for that case with the folowing script (I created a temp table called MUTATING_TMP_TAB (A NUMBER(1):  

CREATE OR REPLACE TRIGGER TRI_BEFORE_I_CREDIT_TAXE
BEFORE INSERT on CREDIT_TAXE
for each row
DECLARE
I         NUMBER := 1;
BEGIN

SELECT A INTO I FROM MUTATING_TMP_TAB;

EXCEPTION
WHEN NO_DATA_FOUND THEN

    INSERT INTO MUTATING_TMP_TAB VALUES (1);

    INSERT INTO CREDIT_TAXE
    VALUES( CFP_SEQNC_PAR.nextval,
        :NEW.ANNEE_COURANT,
        :NEW.MONTANT / 12,
        :NEW.C_TYPE_TAXE,
        189);

    delete from MUTATING_TMP_TAB;

end TRI_AFTER_I_CREDIT_TAXE;
/

This works fine... But my problem is that when I try to use the same logic with a before UPDATE trigger, I does not work!

Here it is :


CREATE OR REPLACE TRIGGER TRI_BEFORE_U_CREDIT_TAXE
before UPDATE on CREDIT_TAXE
for each row
DECLARE

I         NUMBER := 1;

BEGIN

SELECT A INTO I FROM MUTATING_TMP_TAB;

EXCEPTION
WHEN NO_DATA_FOUND THEN

    INSERT INTO MUTATING_TMP_TAB VALUES (1);
    
    update CREDIT_TAXE
    set ANNEE_COURANT = :new.ANNEE_COURANT,
    MONTANT = :new.MONTANT / 12
    where ANNEE_COURANT = :old.ANNEE_COURANT
    and C_TYPE_TAXE = :old.C_TYPE_TAXE
    and C_TYPE_TAUX = 189;


    delete from MUTATING_TMP_TAB;

end TRI_BEFORE_U_CREDIT_TAXE;
/


Have a solution?

RE: Mutating table with a BEFORE UPDATE statement what is the workaround?

  If you have the book, Oracle 8 PL/SQL Programming (Urman, Oracle Press),
there's an example on pages 336 - 340.  It involves having both a row-level trigger
and a statement-level trigger on the table.
  If you don't have the book, let me know.

Jim

oracle, vb, some javascript

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close