在Oracle中将BLOB转换为XMLType XML解析失败

时间:2019-04-11 12:23:02

标签: sql oracle blob xmltype character-set

我无法在Oracle数据库中将BLOB转换为XMLType。 我已经尝试过了:

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

我收到此错误消息:

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.

我的问题是,如何将此BLOB(ISO-8859-2)转换为XMLType? ISO-8859-2的字符ID是什么?

谢谢。

2 个答案:

答案 0 :(得分:1)

使用nls_charset_id获取ID:

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

NLS_CHARSET_ID返回与字符集名称字符串相对应的字符集ID号。

答案 1 :(得分:1)

您可以使用nls_charset_id函数获取字符集ID。

尝试一下:

select
XMLType( BLOB_COLUMN,
         nls_charset_id('EE8ISO8859P2')
   ) as XML
from my_table;