I need to update a query so that it checks that a duplicate entry does not exist before insertion. In MySQL I can just use INSERT IGNORE so that if a duplicate record is found it just skips the insert, but I can’t seem to find an equivalent option for Oracle. Any suggestions?
Share
Check out the MERGE statement. This should do what you want – it’s the
WHEN NOT MATCHEDclause that will do this.Do to Oracle’s lack of support for a true VALUES() clause the syntax for a single record with fixed values is pretty clumsy though:
A different approach (if you are e.g. doing bulk loading from a different table) is to use the “Error logging” facility of Oracle. The statement would look like this:
Afterwards all rows that would have thrown an error are available in the table
errlog. You need to create thaterrlogtable (or whatever name you choose) manually before running the insert usingDBMS_ERRLOG.CREATE_ERROR_LOG.See the manual for details