Search code examples
sqloracle-databaseblobxmltypecharacter-set

BLOB to XMLType XML parsing failed in oracle


I can't convert BLOB to XMLType in oracle database. I've tried this:

select
XMLType( BLOB_COLUMN,
         1 /* this is character set ID. 1 == USASCII | ISO-8859-2 char ID?*/
       ) as XML
from my_table;

I got this error message:

ORA-31011: XML parsing failed
ORA-19202: Error occurred in XML processing
LPX-00200: could not convert from encoding US-ASCII to ISO-8859-2
Error at line 1
ORA-06512: at "SYS.XMLTYPE", line 265
ORA-06512: 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.

My question is, how to convert this BLOB (ISO-8859-2) to XMLType? What is the character ID of ISO-8859-2?

Thanks.


Solution

  • Use nls_charset_id to get ID:

    select
    XMLType( BLOB_COLUMN,
             nls_charset_id('ISO-8859-2')
           ) as XML
    from my_table;
    

    NLS_CHARSET_ID returns the character set ID number corresponding to character set name string.