我在将 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 中移动它。
谢谢!
最佳答案
您可以使用提到的 appendChildXML ,就像这里一样:
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>
关于sql - 在指定位置将 xmltype 插入 xmltype [PL/SQL],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29821779/