本文介绍了在指定位置将xmltype插入xmltype [PL/SQL]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在将xmltype插入到pl/sql中指定位置的另一个xmltype中时遇到问题.

I have problem with insert xmltype into another xmltype in specified place in pl/sql.

第一个变量v_xml的格式为:

First variable v_xml has the form:

<ord>
  <head>
    <ord_code>123</ord_code>
    <ord_date>01-01-2015</ord_date>
  </head>
</ord>

第二个v_xml2:

<pos>
  <pos_code>456</pos_code>
  <pos_desc>description</pos_desc>
</pos>

我的目的是得到这样的东西:

My purpose is get something like this:

<ord>
  <head>
    <ord_code>123</ord_code>
    <ord_date>01-01-2015</ord_date>
  </head>
  <!-- put the second variable in this place - after closing <head> tag -->
  <pos>
    <pos_code>456</pos_code>
    <pos_desc>description</pos_desc>
  </pos>
</ord>

我应该使用我的代码做什么?

What shoud I do with my code?

declare
  v_xml  xmltype;
  v_xml2 xmltype;
begin
  -- some code
  -- some code
  -- v_xml and v_xml2 has the form as I define above
end;

有人可以帮助我解决这个问题吗?据我所知,有像insertchildxml,appendchildxml之类的函数或类似的东西...我在纯SQL中找不到很少的解决方案,但是我不知道如何在PL/SQL中移动它.

Is anyone able to help me with this problem? As I know there are functions like insertchildxml, appendchildxml or something like this...I found few solution in pure SQL, but I don't know how to move this in PL/SQL.

谢谢!

推荐答案

您可以使用提到的 appendChildXML ,如下所示:

You can use mentioned appendChildXML, like here:

declare
  v_xml  xmltype := xmltype('<ord>
                               <head>
                                 <ord_code>123</ord_code>
                                 <ord_date>01-01-2015</ord_date>
                               </head>
                             </ord>');
  v_xml2 xmltype:= xmltype('<pos>
                              <pos_code>456</pos_code>
                              <pos_desc>description</pos_desc>
                            </pos>');
  v_output xmltype;
begin
  select appendChildXML(v_xml, 'ord', v_xml2)
    into v_output from dual;

  -- output result
  dbms_output.put_line( substr( v_output.getclobval(), 1, 1000 ) );
end;

输出:

<ord>
  <head>
    <ord_code>123</ord_code>
    <ord_date>01-01-2015</ord_date>
  </head>
  <pos>
    <pos_code>456</pos_code>
    <pos_desc>description</pos_desc>
  </pos>
</ord>

这篇关于在指定位置将xmltype插入xmltype [PL/SQL]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-22 15:28