简体   繁体   English

Oracle 11g r2中的XML内容修改

[英]XML Content Modification in Oracle 11g r2

I've been dealing with a problem in Oracle XML DB (11g R2) as described below: 我一直在处理Oracle XML DB(11g R2)中的问题,如下所述:

Say in a table with a XMLType column named "xml_document" I have the following xml document 在带有名为“ xml_document”的XMLType列的表中说我有以下xml文档

<?xml encoding="utf-8" ?>
<books>
    <book>
        <author>AUTHORNAME1</author>
        <title>TITLE1</title>
        <price>12.33</price>
    </book>
    <book>
        <author>AUTHORNAME2</author>
        <title>TITLE2</title>
        <price>9.55</price>
    </book>
    <book>
        <author>AUTHORNAME3</author>
        <title>TITLE3</title>
        <price>15.00</price>
    </book>
</books>

Now what I want to do is that replace the titles of all books with "price > 10" as an "-expensive" tag appended. 现在,我要做的是将所有书籍的书名替换为“ price> 10”,并附加“ -expensive”标签。

' for $book in ora:view("XML_TABLE")//books/book where $book/price > 10 return replace value of node $book/title with concat($book/title/text(),"-expensive") '

So after I execute the query in Oracle SQLDeveloper the resulting XML content will be as the following. 因此,在Oracle SQLDeveloper中执行查询后,结果XML内容将如下所示。

<?xml encoding="utf-8" ?>
<books>
    <book>
        <author>AUTHORNAME1</author>
        <title>TITLE1-expensive</title>
        <price>12.33</price>
    </book>
    <book>
        <author>AUTHORNAME2</author>
        <title>TITLE2</title>
        <price>9.55</price>
    </book>
    <book>
        <author>AUTHORNAME3</author>
        <title>TITLE3-expensive</title>
        <price>15.00</price>
    </book>
</books>

I have already tried to do it with UPDATEXML(), XMLQUERY() and XMLTABLE() procedures and still cannot take a step forward. 我已经尝试使用UPDATEXML(),XMLQUERY()和XMLTABLE()过程来做到这一点,但仍然无法向前迈进。

Any help will be appreciated. 任何帮助将不胜感激。

  • when is no XQuery statement (though I cannot tell about Oracle XQuery). when没有XQuery语句(尽管我不能说出Oracle XQuery)。 Try where . 尝试where
  • String concatenation is done using concat(str1, [...], str2) , not the + -operator. 字符串连接使用concat(str1, [...], str2)而非+运算符完成。

Try this query: 试试这个查询:

for $book in ora:view("XML_TABLE")//book
where $book/price > 10
return
  replace value of node $book/title
  with concat($book/title/text(), "-expensive")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM