According to Oracle Docs, string searching is exactly what you need to do:
Recognizing Variables in Messages
To help you find and correct errors, Oracle embeds object names, numbers, and character strings in some messages. These built-in variables are represented by a string, number, or character, as appropriate. For example:
ORA-00020: maximum number of processes (number) exceeded
The previous message might look like this:
ORA-00020: maximum number of processes (50) exceeded
Oracle makes a big conclusion in its docs that strings will be constantly updated in the "Message Accuracy" section. This is a pretty strong suggestion that they intend to do a string search.
In addition, according to this site , the Oracle Error structure also pretty much implies that they intend to perform a string search, since this structure has nothing else for you:
array(4) { ["code"]=>int(942) ["message"]=>string(40) "ORA-00942: table or view does not exist" ["offset"]=>int(14) ["sqltext"]=>string(32) "select * from non_existing_table" }
This output shows the following information:
The $ erris variable is an array with four elements.
The first element is accessible using the key code, and its value is number 942.
The second value is available using the key message, and the value is the string "ORA-00942: table or view does not exist."
The third value is accessible using key offset, and its value is the number 14. This is a character before the file name non-existent table.
The fourth element is a problematic SQL message that causes the error in the first place.
I agree with you; it would be great if there was a better way to get the name of the constraint you are breaking, but string matching seems to be the intended way.
Brian source share