以下 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 之前再次设置正确的编码?