Skip to Main Content

Oracle Database Discussions

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Data base trigger to delete a existing row and insert a the latest row if the value already exists i

3281519Jul 21 2016 — edited Jul 21 2016

Hi

I have a requirement to Create a trigger which triggers before insert to the table, In this trigger it should check for a column's value, if that value already exists then that row must be deleted and latest row should be added.

CREATE OR REPLACE TRIGGER REMOVEDUPLICATES

BEFORE INSERT ON TestTable

REFERENCING OLD AS OL NEW AS NW

FOR EACH ROW

/*WHEN (ID = :NW.ID) */

BEGIN

    DELETE FROM TestTable WHERE ID = :NW.ID;

END;

This trigger is giving below exceptions.

ORA-06512: at "REMOVEDUPLICATES ", line 2

ORA-04088: error during execution of trigger 'REMOVEDUPLICATES'

java.sql.BatchUpdateException: ORA-04091: table TestTable is mutating, trigger/function may not see it

Can some one advice what to do in this case.

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 18 2016
Added on Jul 21 2016
6 comments
1,024 views