为在Oracle中没有根元素的Clob创建xml根元素 [英] Create a xml root element for a clob which does not have a root element in Oracle

查看:69
本文介绍了为在Oracle中没有根元素的Clob创建xml根元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过游标的迭代,我创建了一个具有以下xml格式的CLOB.假设l_tot_clob clob包含以下内容:

By iteration over a cursor I create a CLOB which has below xml format. Suppose l_tot_clob clob contains the below:

<a row="1">
 <b>test</b>
<a>
<a row="2">
 <b>test</b>
</a>

然后,我尝试在另一个名为Record的元素根目录内部放置一个结果,并将结果分配给另一个名为l_return_clob的Clob.的代码如下:

Then I try to put above inside another element root called Record and assign the result to a another clob called l_return_clob. The code for that is below:

SELECT xmlelement("Record" , xmlconcat(xmltype(l_tot_clob))).getclobval() 
INTO l_return_clob
FROM dual;

我期望重新运行l_return_clob是这样的:

What I am expecting from the retrun l_return_clob is something as this:

<Record>
<a row="1">
 <b>test</b>
<a>
<a row="2">
 <b>test</b>
</a>
</Record>

但是正如我所假设的那样,由于l_tot_clob没有父元素,因此在这一点上我试图创建一个根元素作为Record,它给出了以下错误:

But as I assume since the l_tot_clob does not have a parent element so at the point I try to create a root element as Record, it gives the below error:

fdm_ttwof_pkg.main_prc-异常-ORA-31011:XML解析失败 ORA-19202:XML处理LPX-00245时发生错误:多余的数据 文档结束后

fdm_ttwof_pkg.main_prc - Exception -ORA-31011: XML parsing failed ORA-19202: Error occurred in XML processing LPX-00245: extra data after end of document

在这种情况下,如何添加Record元素作为根元素.

How can I add the Record element as the root element in this case.

推荐答案

如果只需要将xml封装在<Record>..</Record>中,而XML则存储在CLOB中,那么为什么不简单地将'<Record>''</Record>'字符串?

If all you need is just to enclose your xml in <Record>..</Record>, and your XML is in CLOB, then why don't you just simply concatenate the '<Record>' and '</Record>' strings?

DECLARE
  v_clob CLOB;
  v_clob_with_root CLOB;
  v_xml xmltype;
BEGIN
  v_clob := '
    <a row="1">
     <b>test</b>
    <a>
    <a row="2">
     <b>test</b>
    </a>';

  v_clob_with_root := '<Record>' || v_clob_with_root || '</Record>';

  v_xml := xmltype(v_clob_with_root); -- no errors, XML is correct
END;

这篇关于为在Oracle中没有根元素的Clob创建xml根元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆