2014-08-30 58 views
2

數據庫(11g)字符集是US7ASCII,我試圖用UTF-8編碼構建一些XML。Oracle - 生成包含多字節字符的XML,LPX-00216錯誤

我正在使用轉換處理(或者所以我在想)US7ASCII到UTF8部分。

示例代碼:

declare 
v_text2 varchar2(100); 
v_text2_conv varchar2(100); 
v_xml varchar2(1000); 
begin 
select building_name into v_text2 from adam_source; -- grab some multibyte data 
select convert(trim(v_text2),'UTF8','US7ASCII') into v_text2_conv from dual; -- convert to UTF8 
select xmlroot(xmlelement("test2",XMLCDATA(v_text2_conv)),version '1.0" encoding="UTF- 8').getclobval() into v_xml from dual; -- Build XML 
dbms_output.put_line(v_xml); -- Display XML 
end; 
/

我得到的錯誤:

ORA-31011: XML parsing failed 
ORA-19202: Error occurred in XML processing 
LPX-00216: invalid character 239 (0xEF) 

任何指針非常感謝!

回答

0
PRG3 SQL> select * from v$version; 

BANNER 
-------------------------------------------------------------------------------- 
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production 
PL/SQL Release 11.2.0.1.0 - Production 
CORE 11.2.0.1.0  Production 
TNS for Linux: Version 11.2.0.1.0 - Production 
NLSRTL Version 11.2.0.1.0 - Production 

PRG3 SQL> select convert(building_name,'UTF8','US7ASCII') from adam_source; 

CONVERT(BUILDING_NAME,'UTF8','US7ASCII') 
-------------------------------------------------- 
�������r�� 



PRG3 SQL> select convert('12345','UTF8','US7ASCII') from dual; 

CONVE 
----- 
12345 

..第一個是一些雙字節字段,第二個是簡單的轉換。

謝謝!

0

這是我如何生成的一些示例數據:

PRG3 SQL> create table adam_test (test char(50)); 

Table created. 

PRG3 SQL> insert into adam_test (select utl_raw.cast_to_varchar2(hextoraw('819B819B92AC8372838B20202020202020202020202020202020202020202020202020202020202020202020202020202020')) from dual); 

1 row created. 

PRG3 SQL> select * from adam_test; 

TEST 
-------------------------------------------------- 
▒▒▒▒▒▒▒r▒▒