我在将 xmltype 插入 pl/sql 中指定位置的另一个 xmltype 时遇到问题。
第一个变量 v_xml 的形式为:
<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>
我的目的是得到这样的东西:
<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>
我应该如何处理我的代码?
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 中移动它。
Thanks!
您可以使用提到的附加ChildXML http://docs.oracle.com/cd/B19306_01/appdev.102/b14259/xdb04cre.htm#CHDFGJHH, 像这儿:
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;
Output:
<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>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)