This discussion is archived
3 Replies Latest reply: Apr 3, 2013 12:29 PM by odie_63 RSS

XML DML XQuery Update syntax

user4423142 Newbie
Currently Being Moderated
Hi everybody,

Certainly my question will appear strange and even stupid , but I want to be sure to use the best syntax and also to be confirmed about some points.
In the document Oracle XML DB Best practices, we can find a lot of statements for modifying XML documents. In page 11 and 12 we have statements with and without XQuery syntax. What is exactly the best way ? Using insertchildxml, updatexml or the update statement with the XMLQuery clause ?
Why we use copy in these statement, but the keyword copy is not used in a XQuery expression.
I think copy is not specific to Oracle, is it used in XQuery language ?
In page 15, the SQL statement to modify XML document uses deletexml, not a XQuery update syntax.

I'm using Oracle 11G.
Thanks in advance for your explanations
  • 1. Re: XML DML XQuery Update syntax
    odie_63 Guru
    Currently Being Moderated
    user4423142 wrote:
    In the document Oracle XML DB Best practices, we can find a lot of statements for modifying XML documents. In page 11 and 12 we have statements with and without XQuery syntax. What is exactly the best way ? Using insertchildxml, updatexml or the update statement with the XMLQuery clause ?
    The recommended way is closely tied to the version you're using, which you didn't give.
    "11g" is not a version, it's a product name.

    You can find the version by running :
    SQL> select * from v$version;
     
    BANNER
    --------------------------------------------------------------------------------
    Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
    PL/SQL Release 11.2.0.3.0 - Production
    CORE     11.2.0.3.0     Production
    TNS for Linux: Version 11.2.0.3.0 - Production
    NLSRTL Version 11.2.0.3.0 - Production
     
    XQuery Update on Oracle in available in the latest version only : 11.2.0.3.
    If you're using this version, Oracle recommends you start using XQuery Update.
    Why we use copy in these statement, but the keyword copy is not used in a XQuery expression.
    I think copy is not specific to Oracle, is it used in XQuery language ?
    <tt>copy</tt> is specific to the XQuery Update Facility (XQUF) extension of the XQuery 1.0 language.

    The XQUF was primarily intended to work with native XML databases where it's OK to directly invoke update primitives (insert, delete, replace etc.) to modify database content.
    On Oracle, it's not possible and the current implementation only supports XQUF through the "transform" operation (copy/modify syntax) where a copy of the original document/fragment is modified and written back to the db.
    However, XQuery rewrite and related optimizations may occur so that piecewise updates actually take place.
  • 2. Re: XML DML XQuery Update syntax
    user4423142 Newbie
    Currently Being Moderated
    Thanks a lot for your answer.

    Sorry for the mistake, 11.2.0.3 is the used version.
    So for you the best way is to use XQUF ?
    I found documents about XQUF and explanations about the keyword copy.
    Does this mean that Oracle can only insert or replace XML fragments into the original document/fragment and needs to make an intermediate operation to get the good document/fragment ?

    Thanks again
  • 3. Re: XML DML XQuery Update syntax
    odie_63 Guru
    Currently Being Moderated
    user4423142 wrote:
    So for you the best way is to use XQUF ?
    I tend to use features recommended by Oracle for the version I have to work with.
    XQUF implementation still has a few bugs (mostly related to structured storage and XQuery rewrite) but I would use it, yes.

    Does this mean that Oracle can only insert or replace XML fragments into the original document/fragment and needs to make an intermediate operation to get the good document/fragment ?
    There are actually two cases to consider :

    1- if the doc is a transient XMLType instance (PL/SQL variable for example) : Oracle applies the update on a copy and return the modified document.
    2- if the doc is stored in an XMLType column (binary XML, object-relational) : whenever possible, Oracle rewrites the query to use the underlying storage model and directly perform piecewise update on the source.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points