我正在尝试更新我的xml数据,但它只允许我更新最多4000个字符。我决定将它们拆分并在循环中更新1000-1000个字符,因此我需要附加xml而不是更新整个内容。
这是我的代码:
首先,我分割给定的数据:
String[] mydata=mydata.split("(?<=\\G.{1000})")
然后我在循环中使用updatexml:
for(int i=0; i<comments.length; i++){
select = "update datadocumentxml d\n" +
" set d.datadocumentxml = updatexml(xmltype(d.datadocumentxml),'/CB_Data/Example/@Comment', ?)\n" +
// " .getClobVal(),\n" +
"
" where d.processengineguid = fnguidjava2raw(?)\n" +
" and d.datadocumentid = 'CB_Data'";
ps = conn.prepareStatement(select);
ps.setString(1,comment);
//ps.setString(1,comments[i]);
ps.setString(2,processid);
rs = ps.executeQuery();
所以基本上我每次都尝试更新数据1000,但是因为我使用的是updatexml所以会覆盖它。
当我运行它时,如果数据是1500个字符,它将只显示最后500个字符,这是非常明显的。但有没有办法更新xml而不覆盖以前的数据?所以我每次都可以在循环中'追加'数据?对不起,如果我不清楚,这是我的第一个问题。
我试图用4000字符限制重现你的问题,因为我无法相信它是这样 - 事实上我没有遇到这个限制(12.1.0.2)。如下所示,此代码也应该是您的解决方案:
create table tst (datadocumentxml clob);
insert into tst values ('<root>');
-- this adds a little over 500 chars, run this 10 times
update tst set datadocumentxml = datadocumentxml || '<send>whistle</send>
<back>
<travel>giant</travel>
<son>844851954</son>
<may>-2056575796.4096966</may>
<larger>
<flow>1293043813</flow>
<since>plastic</since>
<orbit>please</orbit>
<won>angle</won>
<power>-704746039</power>
<molecular>420367029</molecular>
</larger>
<rocky>727548108</rocky>
<youth>-761804169.1209936</youth>
</back>
<tin>attention</tin>
<suddenly>southern</suddenly>
<similar>language</similar>
<rabbit>captain</rabbit>';
-- this adds your example now
update tst set datadocumentxml = datadocumentxml || '<CB_Data><Example Comment = "com1">example text</Example></CB_Data>';
-- before the next line add 10 times the 500 lines again
-- now we add the closing tag
update tst set datadocumentxml = datadocumentxml || '</root>';
commit;
-- this update does now work for me to append 'com2' to the existing comment
update tst d set d.datadocumentxml = updatexml(xmltype(d.datadocumentxml),'/root/CB_Data/Example/@Comment',
(select extractvalue(xmltype(d.datadocumentxml),'/root/CB_Data/Example/@Comment') from tst d)
||' '||'com2').getclobval();
select * from tst;