我正在尝试更新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?这样我就可以每次循环“追加”数据?抱歉,如果我不清楚,这是我的第一个问题。
答案 0 :(得分:0)
我试图用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;