Re: on duplicate key update for triggered table
Posted by:
Rick James
Date: August 23, 2011 08:36AM
OK, maybe that is a good use for TRIGGERs.
If TEST3 has the same fields as TEST2, but with the addition of a TIMESTAMP FIELD at the beginning, you could also record the time at which the dup came in. They body of the trigger would be something like:
BEGIN
INSERT INTO TEST3 (a,b,c) SELECT a,b,c FROM NEW;
END;
Or... TEST3 could reference TEST2:
BEGIN
INSERT INTO TEST3 (id) SELECT id FROM NEW;
END;
This assumes that just the id (the PRIMARY KEY or some UNIQUE key -- one column or a set) is sufficient to tell you what you need. That is, I am assuming there are no other fields you want to capture. Again, TEST3 could have a TIMESTAMP field that will default to the current time.
Or... Your client code could check RowsAffected (or whatever is the right thing) to see when an UPDATE/INSERT fails to do anything (implying a dup).
Subject
Views
Written By
Posted
4430
August 19, 2011 11:59AM
1751
August 21, 2011 09:01AM
1302
August 21, 2011 12:43PM
Re: on duplicate key update for triggered table
1573
August 23, 2011 08:36AM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.