We have a table in Oracle 11g DB which has millions of records. For a few months, we have noticed that duplicate records are getting inserted into the table. Is there any way to alert via email when the duplicate records get inserted into the table? We are in the process of creating a unique index for the table, but it will take sometime. Meanwhile, can an email-alert be created to notify us when duplicate records are getting inserted?
We have OEM installed to monitor this Oracle DB.
If selecting from table takes a long time, I guess you don't want to intercept duplicates as they happen because every insert/update would kill performance even more than it does now.
Therefore, if table isn't in use 24/7, perhaps you could schedule that check and either notify someone or - even better - take action immediately.
That would be a stored procedure, e.g.
Live example, based on Scott's sample schema. I'll create a table that contains
EMP
data, enter some duplicates and delete them.Create a database job; schedule it to run at 02:00 every night
OK, let's now insert some duplicates (all from
deptno = 10
):I won't wait until 02:00 so I'll run the job manually. Remember, its ID is 104?
OK, duplicates are silently deleted.
If you want, you can modify the procedure and - using
UTL_MAIL
package - send an e-mail message to someone. If number of rows deleted is enough, you'd sendSQL%ROWCOUNT
number. Or, send whatever you want.