In trying to extract a subset of data from a Oracle DB table, one of the columns is XMLType, which is extracted with xmlquery() for relevant information.
The problem is that the XML data is from an outside source, which often gives us malformed XML with unescaped special characters.
ORA-31011: XML parsing failed
ORA-19202: Error occurred in XML processing
LPX-00244: invalid use of less-than ('<') character (use <)
Error at line 1
31011. 00000 - "XML parsing failed"
*Cause: XML parser returned an error while trying to parse the document.
*Action: Check if the document to be parsed is valid.
It would be ok for my purposes to ignore these rows.
How can I ignore these parse errors and have Oracle continue on with the SQL statement?
Thanks
Best Answer
I don't think you can directly. I don't know of a way of putting the XML parser into a sort of "lax" mode where it would ignore validation errors, and you can't catch exceptions inside plain SQL.
One approach to deal with this (except harassing your outside source so that they produce valid XML, which is the solution) would be to validate the XML as you store it, and only process data that has been validated. You can do that simple PL/SQL code. Here's a minimal example of one way to approach this.
Sample table and data:
Validation function:
Applying the validation function
You can then query/report based your usual criteria plus the
valid
column.