I'm getting some database errors from an application related to unique constraints however none of the records have any duplicate values so I want to check what query was run that produced the error.
How can I check a history log of queries to pinpoint the problem? I'm using Oracle 12c
Best Answer
There is no such thing enabled by default in the database.
V$
orDBA_HIST
views are not guaranteed to contain all your SQL statements all the time. The amount of memory to store SQL statements inV$
views is limited, andDBA_HIST
views contain only sampled data. Furthermore, they do not store information about constraint violation errors.If you want to find the SQLs causing unique constraint violation errors, you can create a trigger that catches the errors and logs information, for example:
The above trigger catches number
1
errors (that is forORA-00001: unique constraint () violated
) on the top of the stack (that isORA_SERVER_ERROR(1)
) in the database, and logs them in theuserlog
table with the SQL text, so you can find later the SQL statements that caused them.