在 Oracle 中从 CLOB 读取 xml 时检索正确的字符集

问题描述

以下 xml 存储在 Oracle 中的 CLOB 字段中:

<?xml version="1.0" encoding="UTF-8"?>
<module modelCodeValue="TYPE_325" xmlns="http://www.test.com/2008/FMSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <tmEsObj modelCodeScheme="EO" modelCodeSchemeVersion="01" modelCodeValue="ES_OB_1" modelCodeMeaning="EO - desc">
    </tmEsObj>
    <tmProg modelCodeScheme="VO" modelCodeSchemeVersion="01" modelCodeValue="VO_08" modelCodeMeaning="PO- desc">
    </tmProg>
</module>

以下 sql 查询正确更新了标签 tmEsObj 和 tmProg 的属性

UPDATE SR_DATA
  SET XMLDATA =
    XMLTYPE.GETCLOBVAL(XMLQuery('declare default element namespace "http://www.test.com/2008/FMSchema";
        copy $i := $p1 modify
                ((for $j in $i/module/tmEsObj/@modelCodeValue
                  return replace value of node $j with $p2),(for $j in $i/module/tmEsObj/@modelCodeMeaning
                  return replace value of node $j with $p3),(for $j in $i/module/tmProg/@modelCodeValue
                  return replace value of node $j with $p4),(for $j in $i/module/tmProg/@modelCodeMeaning
                  return replace value of node $j with $p5)  
                )
                return $i'
             PASSING XMLType(xmldata) AS "p1",'ES_OB_1a' AS "p2",'EO ASI - desc' AS "p3",'VO_08e' AS "p4",'PO ASI - desc' AS "p5"
             RETURNING CONTENT))

但是正如您从生成的 xml 中看到的那样,编码已更改

<?xml version="1.0" encoding="ISO-8859-1"?>
<module modelCodeValue="TYPE_325" xmlns="http://www.test.com/2008/FMSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <tmEsObj modelCodeScheme="EO" modelCodeSchemeVersion="01" modelCodeValue="ES_OB_1a" modelCodeMeaning="EO ASI - desc">
    </tmEsObj>
    <tmProg modelCodeScheme="VO" modelCodeSchemeVersion="01" modelCodeValue="VO_08e" modelCodeMeaning="PO ASI - desc">
    </tmProg>
</module>

有没有办法告诉系统从一开始就考虑正确的编码?否则如何在更新 xml 之前再次设置正确的编码?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)