1

How can I remove a node from xmltype using PL/SQL? Example:

<people>
   <person>
      <personNO>1</personNO>
   </person>
   <person>
      <personNO>2</personNO>
   </person>
</people>

I try to remove whole node person if /people/person/personNO is 1. My xml document is in the l_xml xmltype variable. So far I've got:

SELECT deletexml(l_xml, '/people/person[personNO="1"]')
INTO l_xml
FROM dual;

It doesn't seem to work at all. Can you please suggest any solution?

4

1 回答 1

4

定义“根本不起作用”,因为它可以正常工作:

(在 10.2.0.4 + 11.2.0.3 上测试)

SQL> declare
  2    l_xml xmltype;
  3  begin
  4
  5    l_xml := xmltype.createXML('<people>
  6     <person>
  7        <personNO>1</personNO>
  8     </person>
  9     <person>
 10        <personNO>2</personNO>
 11     </person>
 12  </people>');
 13
 14    select deletexml(l_xml, '/people/person[personNO="1"]')
 15      into l_xml
 16      from dual;
 17
 18    dbms_output.put_line(l_xml.getstringval());
 19  end;
 20  /
<people><person><personNO>2</personNO></person></people>

PL/SQL procedure successfully completed.

所以 person no = 1 的整个 person 节点被删除。如果您打算清除每个节点(如果 personNO 1 存在于其中任何一个节点中),那么您希望将 xpath 设置为/people/person[../person/personNO="1"]

于 2013-04-11T14:33:45.620 回答