我正在使用oracle 11.2.0.3。我有一个XMLType列,其结构如下:
<section>
<question questionID="1">
<answer>US</answer>
<answer>XX</answer>
</question>
</section>
我需要删除第二个节点,以便在更新后 - 我留下以下内容:
<section>
<question questionID="1">
<answer>US</answer>
</question>
</section>
我一直在尝试各种查询而没有成功。根据我的研究,我认为下面的查询可行 - 但事实并非如此。我收到XX行更新的消息,但是当我查询xml时 - 我想删除的节点仍然存在!我在这里缺少什么?
update SECTION s set s.section_xml = deleteXML(s.section_xml, '//question[@questionID=1]/answer[2]')
感谢您的帮助!!!!!
答案 0 :(得分:1)
您的查询确实,至少在11.2.0.2.0:
SQL> CREATE TABLE SECTION AS
2 SELECT XMLTYPE('<section>
3 <question questionID="1">
4 <answer>US</answer>
5 <answer>XX</answer>
6 </question>
7 </section>') section_xml FROM dual;
Table created
SQL> UPDATE SECTION s
2 SET s.section_xml = deleteXML(s.section_xml,
3 '//question[@questionID=1]/answer[2]');
1 row updated
SQL> SELECT s.section_xml.getClobVal() FROM SECTION s;
S.SECTION_XML.GETCLOBVAL()
--------------------------------------------------------------------------------
<section>
<question questionID="1">
<answer>US</answer>
</question>
</section>