XMLType - reorganize nodes?

I tried to migrate Berkeley DB XML to Oracle XML DB. Each container of Berkeley DB XML has become one table of relational database in Oracle XML DB with an XMLType column to contain the XML document:
CREATE TABLE MyTable 
    (
        id VARCHAR2(1024) PRIMARY KEY, 
        xml XMLTYPE NOT NULL
    ) XMLType COLUMN Xml STORE AS CLOB 
      XMLSCHEMA "http://xmlns.abc.de/xdb/schemas/RTIDB/abcfinlib.xsd" ELEMENT "abcfinlib"
In my application Java migration I ask Berkeley DB XML XML document and insert it on the fly in the appropriate Oracle XML DB table.

When I now selects the document XML of the Berkeley DB XML and the Oracle XML DB (to check if the copy has been a success and the two XML documents an equal somehow) XML documents are not equal because parts of the XML in the Oracle XML DB are placed in other locations in the XML document.
What is a behavior known to Oracle XML DB? I have to say one other thing when creating the database table?
How can I stop rearraning the XML document?

Oracle 11g 11.2

I created a problem where no problem is not at all? ;)

Looks like so much ;)

Tags: Oracle Development

Similar Questions

  • Extract data from complex XML of XMLType with nodes parents containing several internal nodes

    Hello

    I use Google geocoding XML Web Service to try to enrich some geo data in the database. I've kept all the Google result in an XMLType column, the result is something like this:

    <? XML version = "1.0" encoding = "UTF-8"? >

    < GeocodeResponse >

    < status > OK < / status >

    < result >

    Zip_code < type > < / type >

    < formatted_address > 76279, Saudi Arabia < / formatted_address >

    < address_component >

    < > 76279 long_name < / long_name >

    < > 76279 short_name < / short_name >

    Zip_code < type > < / type >

    < / address_component >

    < address_component >

    < long_name > Northern Frontier Province < / long_name >

    < short_name > Northern Frontier Province < / short_name >

    administrative_area_level_1 < type > < / type >

    < Type > policy < / type >

    < / address_component >

    < address_component >

    < long_name > Saudi Arabia < / long_name >

    < short_name > SA < / short_name >

    country of < type > < / type >

    < Type > policy < / type >

    < / address_component >

    < geometry >

    < location >

    < lat > 29.1214197 < / lat >

    < LNG > 44.3945656 < / LNG >

    < / location >

    < location_type > APPROX. < / location_type >

    < window >

    < Southwest >

    < lat > 29.1016132 < / lat >

    < LNG > 44.3654665 < / LNG >

    < / Southwest >

    < Northeast >

    < lat > 29.1400926 < / lat >

    < LNG > 44.4116001 < / LNG >

    < / Northeast >

    < / window >

    < limits >

    < Southwest >

    < lat > 29.1016132 < / lat >

    < LNG > 44.3654665 < / LNG >

    < / Southwest >

    < Northeast >

    < lat > 29.1400926 < / lat >

    < LNG > 44.4116001 < / LNG >

    < / Northeast >

    < / delimits >

    < / geometry >

    < place_id > ChIJcy767DIAYxURohAm-DLSunw < / place_id >

    < / result >

    < result >

    locality < type > < / type >

    < Type > policy < / type >

    Foucart, France < formatted_address > < / formatted_address >

    < address_component >

    < long_name > Foucart < / long_name >

    < short_name > Foucart < / short_name >

    locality < type > < / type >

    < Type > policy < / type >

    < / address_component >

    < address_component >

    < long_name > Seine-Maritime < / long_name >

    < > 76 short_name < / short_name >

    administrative_area_level_2 < type > < / type >

    < Type > policy < / type >

    < / address_component >

    < address_component >

    < long_name > upper Normandy < / long_name >

    < short_name > upper Normandy < / short_name >

    administrative_area_level_1 < type > < / type >

    < Type > policy < / type >

    < / address_component >

    < address_component >

    < long_name > France < / long_name >

    < short_name > EN < / short_name >

    country of < type > < / type >

    < Type > policy < / type >

    < / address_component >

    < geometry >

    < location >

    < lat > 49.6131170 < / lat >

    < LNG > 0.5951040 < / LNG >

    < / location >

    < location_type > APPROX. < / location_type >

    < window >

    < Southwest >

    < lat > 49.6019770 < / lat >

    < LNG > 0.5731880 < / LNG >

    < / Southwest >

    < Northeast >

    < lat > 49.6329760 < / lat >

    < LNG > 0.6081609 < / LNG >

    < / Northeast >

    < / window >

    < limits >

    < Southwest >

    < lat > 49.6019770 < / lat >

    < LNG > 0.5731880 < / LNG >

    < / Southwest >

    < Northeast >

    < lat > 49.6329760 < / lat >

    < LNG > 0.6081609 < / LNG >

    < / Northeast >

    < / delimits >

    < / geometry >

    < place_id > ChIJQdTiHHJc4EcRUIO2T0gUDAQ < / place_id >

    < / result >

    < / GeocodeResponse >


    Here are practically two entries from geo (the /result of xml nodes), and each entry has multiple secondary entries of type address_component and a secondary entrance to the geometry of type.


    I can get the entries in the result of this query:


    SELECT xt.*

    OF zip_tree_sort_xml x,.

    XMLTABLE ("' / GeocodeResponse/result")

    PASSAGE x.google_geodata_xml

    COLUMNS

    Path of 'FORMATTED_ADDRESS' VARCHAR2 (200) "formatted_address".

    ) xt;


    The subnodes XML type address_component and type geometry of teas and those below:


    SELECT xt.*

    OF zip_tree_sort_xml x,.

    XMLTABLE ('/ GeocodeResponse/result/address_component ')

    PASSAGE x.google_geodata_xml

    COLUMNS

    Path of "LONG_NAME' VARCHAR2 (200)"long_name. "

    'SHORT_NAME' VARCHAR2 (500) PATH 'short_name ',.

    Path ACCESS VARCHAR2 (200) from 'TYPE_1' 'type [1]. "

    Path ACCESS VARCHAR2 (200) to 'TYPE_2' 'type [2].

    ) xt;


    SELECT xt.*

    OF zip_tree_sort_xml x,.

    XMLTABLE ("/ GeocodeResponse/result/geometry/location")

    PASSAGE x.google_geodata_xml

    COLUMNS

    "latitude" NUMBER PATH 'lat ',.

    "longitude" NUMBER PATH 'LNG '.

    ) xt;


    But y at - it anyway to join the two subnodes XML below with the parent that above? So I can only get correct result attributes?

    Best regards

    Rodriguez

    But y at - it anyway to join the two subnodes XML below with the parent that above? So I can only get correct result attributes?

    You can do chaining XMLTABLE another that will handle the address_component expandable nodes.

    Data from the geometry node can be extracted at the same level as a result.

    SQL> select x1.formatted_address
      2       , x2.long_name
      3       , x2.short_name
      4       , x2.type_1
      5       , x2.type_2
      6       , x1.latitude
      7       , x1.longitude
      8  from zip_tree_sort_xml t
      9     , xmltable('/GeocodeResponse/result'
     10         passing t.google_geodata_xml
     11         columns
     12           formatted_address   varchar2(200) path 'formatted_address'
     13         , address_components  xmltype       path 'address_component'
     14         , latitude            number        path 'geometry/location/lat'
     15         , longitude           number        path 'geometry/location/lng'
     16       ) x1
     17     , xmltable('/address_component'
     18         passing x1.address_components
     19         columns
     20           long_name   varchar2(200) path 'long_name'
     21         , short_name  varchar2(500) path 'short_name'
     22         , type_1      varchar2(200) path 'type[1]'
     23         , type_2      varchar2(200) path 'type[2]'
     24       ) x2 ;
    
    FORMATTED_ADDRESS       LONG_NAME                   SHORT_NAME                   TYPE_1                         TYPE_2       LATITUDE  LONGITUDE
    ----------------------- --------------------------- ---------------------------- ------------------------------ ---------- ---------- ----------
    76279, Saudi Arabia     76279                       76279                        postal_code                               29,1214197 44,3945656
    76279, Saudi Arabia     Northern Borders Province   Northern Borders Province    administrative_area_level_1    political  29,1214197 44,3945656
    76279, Saudi Arabia     Saudi Arabia                SA                           country                        political  29,1214197 44,3945656
    Foucart, France         Foucart                     Foucart                      locality                       political   49,613117   0,595104
    Foucart, France         Seine-Maritime              76                           administrative_area_level_2    political   49,613117   0,595104
    Foucart, France         Upper Normandy              Upper Normandy               administrative_area_level_1    political   49,613117   0,595104
    Foucart, France         France                      FR                           country                        political   49,613117   0,595104
    
    7 rows selected.
    
  • Add the xmltype attribute node

    How can I add an attribute node to xml in an xmltype?
    Say that I
    declare
      t_xml xmltype;
    begin
      t_xml := xmltype( '<x a="1"/>' );
    end;
    How can I manipulate this variable t_xml become
    <x a="1" b="2"/>
    Anton

    Depends on the version.

    Before 11.2.0.3:

    SQL> with t as (  select xmltype('') as t_xml from dual )
      2  select insertchildxml(
      3           t_xml
      4         , '/x'
      5         , '@b'
      6         , '2'
      7         )
      8  from t;
    
    INSERTCHILDXML(T_XML,'/X','@B'
    --------------------------------------------------------------------------------
    
     
    

    On 11.2.0.3, by using XQuery Update:

    select /*+ no_xml_query_rewrite */
           xmlquery(
            'copy $d := .
             modify ( insert node attribute b {$val} into $d/x )
             return $d'
            passing t_xml
                  , '2' as "val"
            returning content
           )
    into t_xml
    from dual
    ;
    

    (not tested, but should be close)

    Marco Gralike wrote:
    You should be able to build up the little together 'back' in a dynamic method, but for now, don't ask me how (mark)?

    The generic approach would require market the entire tree down recursively to the copy existing nodes and add the new in the right place.
    Although XQuery (without involving XQUF) can do it, it's more of a task for XSLT:

    SQL> with t as (  select xmltype('') as t_xml from dual )
      2  select xmltransform(
      3           t_xml
      4         , xmlparse(document
      5  '
      6    
      7    
      8    
      9      
     10        
     11      
     12    
     13    
     14      
     15        
     16      
     17    
     18  '
     19           )
     20         , q'{att="'2'"}'
     21         )
     22  from t;
    
    XMLTRANSFORM(T_XML,XMLPARSE(DO
    --------------------------------------------------------------------------------
    
    
     
    
  • predicates on xmltype column nodes

    Hello
    Here, I'll send 2 files with table. What I need is the value of element < sno > who < name > is Tamil or Ravi and keyid = 111 record
    In other words I'm looking for output is 102888 (102 is Tamil sno and 888 for happy).

    with a (too)
    SELECT ("< class > xmltype
    < student >
    < name > Raju < / name >
    < sno > 101 < / sno >
    < / student >
    < student >
    < name > Tamil < / name >
    < > 102 sno < / sno >
    < / student >
    < student >
    Delighted to < name > < / name >
    < > 888 sno < / sno >
    < / student >
    (< / class > ') performance(1), keyid ' 111'
    OF the double
    Union of all the
    SELECT ("< class > xmltype
    < student >
    < name > Tamil < / name >
    < > 108 sno < / sno >
    < / student >
    < student >
    < name > Alex < / name >
    < sno > 208 < / sno >
    < / student >
    (< / class > ') performance(1), '222' keyid FROM dual
    ) A.keyid, a.result1 SELECTION of a


    Thank you
    Ravi

    Hello

    Do you really need concatenated values, or you are really looking for separate lines?

    Assuming a version:

    SQL> with a as (
      2  SELECT xmltype('
      3  
      4  Raju
      5  101
      6  
      7  
      8  Tamil
      9  102
     10  
     11  
     12  Ravi
     13  888
     14  
     15  ') result1,'111' keyid
     16  FROM dual
     17  union all
     18  SELECT xmltype('
     19  
     20  Tamil
     21  108
     22  
     23  
     24  Alex
     25  208
     26  
     27  ') result1,'222' keyid FROM dual
     28  )
     29  select xmlcast(
     30           xmlquery('/class/student[name="Tamil" or name="Ravi"]/sno'
     31                    passing a.result1
     32                    returning content)
     33           as varchar2(30)
     34         )
     35  from a
     36  where keyid = '111'
     37  ;
    
    XMLCAST(XMLQUERY('/CLASS/STUDE
    ------------------------------
    102888
     
    
  • Extract a specific node of XMLTYPE value

    I have a piece of code that puts an answer Google geocoding in an XMLTYPe variable.  I then use lines similar to the following to retrieve values such as address and location:

    px_xml.EXTRACT('/GeocodeResponse[1]/result['||pn_result_number||']/formatted_address[1]/text()').getstringval();
    

    It's a pretty lazy way of just looping through my results and picking a specific value.

    Now, I need to extract just the addresses zip_code of XML component and can't do in the same way.  Someone at - it ideas?

    A call to the example is:

    https://maps.googleapis.com/maps/API/geocode/XML?address=London+Eye & Bounds = 49.90878, - 7.69042. 60.88770,-0.83496 & key =

    but you need to add your own key to operate.  There are several components of the address and I just want to identify who has the type "zip_code".

    Thank you!

    It's a pretty lazy way of just looping through my results and picking a specific value.

    And what about using a more friendly approach, XMLTABLE namely:

    Extract data from complex XML of XMLType with nodes parents containing several internal nodes

    Use an XPath predicate to target only the required component, for example:

    select x.long_name
    from xmltable('/GeocodeResponse/result'
           passing px_xml
           columns
             long_name   varchar2(200) path 'address_component[type="postal_code"]/long_name'
         ) x
    ;
    
  • Formatting XML in VARCHAR2

    Hello

    I am interested in an XML file/feed, and in it there are points and page breaks (< para >,
    ). When I extract the data in a field in varchar2, I want to preserve the structure of the paragraph/pause...

    for example
    SELECT   text_col
    FROM     XMLTABLE('/'
                      PASSING (xmltype('<para>This is paragraph 1.<br/>This is p1, line 1.<br/>This is p1, line 2.</para>'))
                      COLUMNS text_col VARCHAR2(1000) PATH '/'
                     );
    gives
    This is paragraph 1.This is p1, line 1.This is p1, line 2.
    What I'm after is:
    This is paragraph 1.
    This is p1, line 1.
    This is p1, line 2.
    Is it achievable?

    Oracle Database 10 g Enterprise Edition Release 10.2.0.4.0 - 64 bit

    Thank you.

    Hello

    11g, I would like to use this:

    SQL> select text
      2  from xmltable(
      3       'string-join(
      4        for $i in /para/node()
      5        return
      6          typeswitch ($i)
      7            case text()      return string($i)
      8            case element(br) return "
    "
      9            default return ""
     10        , "")'
     11       passing xmlparse(content 'Line1
    Line2
    Line3
    ') 12 columns text varchar2(2000) path '.' 13 ) 14 ; TEXT -------------------------------------------------------------------------------- Line1 Line2 Line3

    but I'm not sure it works on your version. You can try however.

    Another solution would be:

    SQL> select utl_i18n.unescape_reference(replace(x.text.getstringval(), '
    ', ' ')) as text 2 from xmltable('/para' 3 passing xmltype('Line1&Line1.1
    Line2
    Line3
    ') 4 columns text xmltype path 'node()' 5 ) x 6 ; TEXT -------------------------------------------------------------------------------- Line1&Line1.1 Line2 Line3
  • Funny problem with generating xml looks like table.

    Hello
    I have the following problem:

    1.I has table:
    CREATE TABLE DESCRIPTION
    (
    NUMBER OF DESC_ID
    SK VARCHAR2 (500 BYTE),
    OF VARCHAR2 (500 BYTE).
    EN VARCHAR2 (500 BYTE)
    )

    2.I need to create an xml looks like:

    < "NODE1" >
    < "NODE2" >
    data column < /de > < >
    column < www.tourocloudbackup.com > < en > data
    given < sk > column < /sk > sk
    < / "NODE2" >
    < / "NODE1 >"

    where "PAR1" and "PAR2" is CASE-SENSITIVE SETTING of RESPECT.

    3. I create for that to be the next function:


    CREATE or REPLACE FUNCTION F_CREATE_XML_DESC (inDescId, NUMBER of)
    inNode1 VARCHAR2,
    inNode2 VARCHAR2)
    RETURN OF XMLTYPE
    IS
    tmpVar NUMBER;
    /******************************************************************************


    ******************************************************************************/
    vXml XMLTYPE.

    CTX DBMS_XMLGEN.ctxHandle;
    vColumnList VARCHAR2 (1000);
    vXmlStr VARCHAR2 (1000);

    BEGIN


    If (inDescId is not null) then
    SELECT SUBSTR (list) of LENGTH (list) - 1, 1,
    IN vColumnList
    FROM (SELECT (LISTAGG (COLUMN_NAME |))) ',')
    TO WITHIN THE GROUP (ORDER OF COLUMN_NAME))
    As a list
    Of user_tab_columns
    WHERE table_name = 'DESCRIPTION' AND COLUMN_NAME <>'DESC_ID');


    CTX: =.
    DBMS_XMLGEN.
    NewContext)
    "select".
    || vColumnList
    || "description d where d.desc_id ='".
    || inDescId);

    on the other
    -yesterday to return null if DESC_ID is null
    Returns a null value.

    SELECT SUBSTR (list) of LENGTH (list) - 1, 1,
    IN vColumnList
    FROM (SELECT (LISTAGG ("'"' |))) "ACE" | COLUMN_NAME | ' ,')
    TO WITHIN THE GROUP (ORDER OF COLUMN_NAME))
    As a list
    Of user_tab_columns
    WHERE table_name = 'DESCRIPTION' AND COLUMN_NAME <>'DESC_ID');

    CTX: =.
    DBMS_XMLGEN.
    NewContext)
    "select".
    || vColumnList
    || "of the double");


    end if;

    -DBMS_XMLGEN.setRowSetTag (ctx, inNode1);
    DBMS_XMLGEN.setRowTag (ctx, 'NŒUD');
    DBMS_XMLGEN. SETNULLHANDLING (ctx, 2);

    -I DON'T KNOW WHY THIS DOESN'T WORK!
    -DBMS_XMLGEN.useLowerCaseTagNames ();


    vXmlStr: low = (DBMS_XMLGEN.getxml (ctx));

    DBMS_XMLGEN. CLOSECONTEXT (ctx);

    If (inNode1 is not null and)
    inNode2 is not null) then

    Select xmlelement (EVALNAME (inNode1),
    XmlElement (EVALNAME (inNode2),
    Extract (XmlType (vXMLStr), '//node/*')))
    in vXml
    Double;
    end if;

    If (inNode1 is null and)
    inNode2 is not null) then

    Select xmlelement (EVALNAME (inNode2),
    Extract (XmlType (vXMLStr), '//node/*'))
    in vXml
    Double;
    end if;


    If (inNode1 is not null and)
    inNode2 is null) then

    Select xmlelement (EVALNAME (inNode1),
    Extract (XmlType (vXMLStr), '//node/*'))
    in vXml
    Double;
    end if;



    VXML BACK;
    END F_CREATE_XML_DESC;
    /


    4 Requriments:
    If I add the new column to the table Description the XML should include this new column.
    Problem is a RESPECT for the CASE, the table tags MUST be LOWER case, and of course without column DESC_ID, BUT the two NODE1 and NODE2 SHOULD be case-sensitive.

    5. function whihch I cooked up in my opinion is not fast enough. IS THERE a SOLUTION to make this better? Help, please.

    6 DB: Oracle 11 g R2.

    Edited by: kozand 2011-06-26 05:06

    Hello

    -I DON'T KNOW WHY THIS DOESN'T WORK!
    -DBMS_XMLGEN.useLowerCaseTagNames ();

    I don't see in the package specification.

    I'm not a big fan of this but you can try the following solutions:

    SQL> DECLARE
      2
      3   inNode1      varchar2(30) := 'NODE1';
      4   inNode2      varchar2(30) := 'NODE2';
      5   inDescId     number := 1;
      6
      7   colList      varchar2(4000);
      8
      9   xml_data     xmltype;
     10   doc          clob;
     11
     12  BEGIN
     13
     14   SELECT listagg(column_name || ' as "' || lower(column_name) || '"', ',') within group (order by column_name)
     15   INTO colList
     16   FROM user_tab_columns
     17   WHERE table_name = 'DESCRIPTION'
     18   AND column_name != 'DESC_ID';
     19
     20   EXECUTE IMMEDIATE 'SELECT XMLForest(' || colList || ') FROM description WHERE desc_id = :1'
     21   INTO xml_data
     22   USING inDescId;
     23
     24   SELECT nvl2( inNode1
     25              , XMLElement(evalname(inNode1), xml_data)
     26              , xml_data )
     27   INTO xml_data
     28   FROM (
     29     SELECT nvl2( inNode2
     30                , XMLElement(evalname(inNode2), xml_data)
     31                , xml_data ) as xml_data
     32     FROM dual
     33   );
     34
     35   dbms_output.put_line(xml_data.getclobval());
     36
     37  END;
     38  /
    
    data from column dedata from column endata from column sk
    
    PL/SQL procedure successfully completed
     
    

    Or a single XQuery:

    SQL> show user
    User is "dev"
    
    SQL>
    SQL> SELECT XMLSerialize(document
      2    XMLQuery(
      3      'let $data :=
      4         for $i in fn:collection("oradb:/DEV/DESCRIPTION")/ROW
      5         where $i/DESC_ID = $id
      6         return
      7           for $j in $i/child::*
      8           let $node-name := name($j)
      9           where $node-name != "DESC_ID"
     10           return element {fn:lower-case($node-name)} {fn:data($j)}
     11       let $node2 := if ($inNode2) then element {$inNode2} {$data} else ($data)
     12       return if ($inNode1) then element {$inNode1} {$node2} else ($node2)'
     13      passing cast(1 as number) as "id"
     14            , 'NODE1' as "inNode1"
     15            , 'NODE2' as "inNode2"
     16      returning content
     17    )
     18    as clob indent
     19  )
     20  FROM dual
     21  ;
    
    XMLSERIALIZE(DOCUMENTXMLQUERY(
    --------------------------------------------------------------------------------
    
      
        data from column sk
        data from column de
        data from column en
      
    
     
    
  • Do I need my own taste?

    I have a treeview, and I'm currently implementing drag drop the widgets reorganization (identical to the Panel style). Here are some of the questions, I'm having a hard time understanding.

    1. Is it necessary to set up my own taste. Each node represents an xml element that is stored in the memory of the plug-in and reorganize nodes will have to reorder items.
    2. How do you get a unique alphanumeric combination for your own flavor, it's something that should be saved, and why is it different for Windows and Mac
    3. During the reorganization, changes to widgets in the treeview do it manually or treeview should be reset and filled with the underlying xml structure. (However if refresh is performed, then the treeview will lose status, reset all the closed nodes?)

    Thank you for any advice, assistance, or even sympathy

    (1) own flavor? Yes, you have your own data type and a separate model that will not work for the other SD objectives.

    XML support that you mention. As a general rule, would mean a drag of your object in the view of the structure (XML layout window sidebar) you instantiate a XMLElement there? Your palette would accept view structure from wildfire?

    There are a lot of examples if you are looking for the CDataExchangeHandlerFor SDK.

    (2) a good idea would be to reuse the script corresponding to your model class ScriptID.

    If (probably not) you need an external Windows flavor, use RegisterExternalFlavor to save your flavor of chain.

    (3) decouple your model tree. Do not strictly follow the examples, they are too simplified. Read about lazy notifications (e.g. TreeLazyNotificationData) - they are used to see updates of UI until they fit into.

    Dirk

  • Insert node xmltype

    He said this support oracle xml db xquery 1.0 and xquery update 1.0.

    I want to insert a node in the xmltype column.

    My like this xmltype column:

    < + photos >

    < default pic = "yes" >

    < master > 1.jpg < / master >

    1_thumb.jpg < go > < / inch >

    < / pic >

    < pic >

    < master > 2.jpg < / master >

    2_thumb.jpg < go > < / inch >

    < / pic >

    < pic >

    < master > 3.jpg < / master >

    3_thumb.jpg < go > < / inch >

    < / pic >

    < pic >

    < master > 4.jpg < / master >

    4_thumb.jpg < go > < / inch >

    < / pic >

    < / photos >

    My update sql like this: (the xmlquery is see xquery update 1.0)

    Update t set t.info XML = xmlquery ('declare variable $e: = $d / / pic [last ()]; insert $e into node $d/pics ' PASSING t.info have "d" RETURNING CONTENT) where t.id =: id and t.info is not null

    It went wrong: ORA-18150

    There is little reference to the update of xquery sql introduction.

    He said this support oracle xml db xquery 1.0 and xquery update 1.0.

    XQuery Update is available since version 11.2.0.3, but only the "transform" model of treatment is supported:

    SQL> with txml (info) as (
      2    select xmlparse(document
      3  '
      4    
      5      1.jpg
      6      1_thumb.jpg
      7    
      8    
      9      2.jpg
    10      2_thumb.jpg
    11    
    12    
    13      3.jpg
    14      3_thumb.jpg
    15    
    16    
    17      4.jpg
    18      4_thumb.jpg
    19    
    20  ')
    21    from dual
    22  )
    23  select xmlserialize(document
    24           xmlquery(
    25             'copy $d := .
    26              modify (
    27                insert node $d/pics/pic[last()] into $d/pics
    28              )
    29              return $d'
    30             passing t.info
    31             returning content
    32           )
    33           indent
    34         )
    35  from txml t;
    
    XMLSERIALIZE(DOCUMENTXMLQUERY(
    --------------------------------------------------------------------------------
    
      
        1.jpg
        1_thumb.jpg
      
      
        2.jpg
        2_thumb.jpg
      
      
        3.jpg
        3_thumb.jpg
      
      
        4.jpg
        4_thumb.jpg
      
      
        4.jpg
        4_thumb.jpg
      
    
    

    There is little reference to the update of xquery sql introduction.

    XQuery and Oracle XML DB

    Querying and updating of XML data

    Best practices for XQuery in Oracle Database 12c

  • extraction of xmltype table in the xml output: redundant nodes

    Hi guys - see example below.  (edit: Sorry, did not use these forums for a while and can't seem to understand how to format the code...)

    [code] SQL > select *.

    the v version $2;

    BANNER

    --------------------------------------------------------------------------------

    Oracle Database 11 g Enterprise Edition Release 11.2.0.4.0 - 64 bit Production

    PL/SQL Release 11.2.0.4.0 - Production

    CORE Production 11.2.0.4.0

    AMT for Linux: Version 11.2.0.4.0 - Production

    NLSRTL Version 11.2.0.4.0 - Production

    [/ code]

    [/ code]

    SQL > create table mytesttable (item_id issue, x_data xmltype);

    Table created.

    SQL >

    SQL > insert into mytesttable

    2 with dat (select ' blah' point of double

    3 Union all the

    4 Select "blah" more than double)

    5, t as (select xmlelement ("x_data"

    6, xmlattributes (1 as "dummyattr")

    7, xmlagg (xmlelement ("item"

    8                                                ,item))

    9                              ) x_data

    10 dat

    11              )

    12. Select 1, x_data

    13 t;

    1 line of creation.

    SQL >

    SQL > select *.

    2 of mytesttable;

    ITEM_ID

    ----------

    X_DATA

    ---------------------------------------------------------------------------------------------

    -------

    1

    < x_data dummyattr = "1" >

    < item > blah < / item >

    < element > more blah < / item >

    < / x_data >

    1 selected line.

    SQL >

    SQL > select xmlelement ("outerelement"

    2, xmlelement ("itemID", item_id)

    3, xmlelement ("x_data", x_data)

    4                   )

    5 mytesttable;

    XMLELEMENT ("OUTERELEMENT", XMLELEMENT("ITEMID",ITEM_ID), XMLELEMENT("X_DATA",X_DATA))

    ---------------------------------------------------------------------------------------------

    -------

    < outerelement > < itemID > 1 < / itemID > < x_data > < x_data dummyattr = "1" >

    < item > blah < / item >

    < element > more blah < / item >

    < / x_data >

    < / x_data > < / outerelement >

    1 selected line.

    [/ code]

    Like the above, I have an xmltype in a table that has other non-xmltype columns.   I have a requirement to extract them out in a single xml document in a manner similar to the last SQL it.

    the problem is that if I do it according to the foregoing, I add a redundant node artificially.  the first node < x_data > is not necessary, but how can I go and add the xmltype column to the result without having to qualify it with another element around it?

    know how to do the following:

    < outerelement > < itemID > 1 < / itemID > < x_data dummyattr = "1" >

    < item > blah < / item >

    < element > more blah < / item >

    < / x_data > < / outerelement >

    ?

    Too bad... I had a moment mute:

    Select xmlelement ("outerelement"

    xmlelement ("itemID", item_id)

    x_data

    )

    of mytesttable;

  • Add several different nodes from one xmltype to another

    Hello

    Given the two following bits of XML:

    < root >
    < xmlnode >
    val1 < subnode1 > < / subnode1 >
    val2 < subnode2 > < / subnode2 >
    < / xmlnode >
    < xmlnode >
    val3 < subnode1 > < / subnode1 >
    < subnode2 > val4 < / subnode2 >
    < / xmlnode >
    < / root >

    < a >
    < b > < /b > valb
    valc < c >/< c >
    < d >
    vald1 < d1 > < / d1 >
    < d2 > vald2 < / d2 >
    / < d: >
    Vale of < e > < /e >
    valf < f > < /f >
    < g >
    valg1 < g1 > < / g1 >
    valg2 < g2 > < / g2 >
    / < g >
    < h >
    valh1 < h1 > < / h1 >
    valh2 < h2 > < / h2 >
    < HR >
    < /a >

    I need to insert a few nodes of the second xml in a new node at the top of the first xml, as follows:

    < root >

    < InfosSuppl >

    < b > < /b > valb

    < d >

    vald1 < d1 > < / d1 >

    < d2 > vald2 < / d2 >

    / < d: >

    valf < f > < /f >

    < h >

    valh1 < h1 > < / h1 >

    valh2 < h2 > < / h2 >

    < HR >

    < / extrainfo >

    < xmlnode >

    val1 < subnode1 > < / subnode1 >

    val2 < subnode2 > < / subnode2 >

    < / xmlnode >

    < xmlnode >

    val3 < subnode1 > < / subnode1 >

    < subnode2 > val4 < / subnode2 >

    < / xmlnode >

    < / root >

    At the time I thought that I had to only add a few nodes (eg. b and f), I used:

    with sample_data as (select xmltype ("< root >

    < xmlnode >

    val1 < subnode1 > < / subnode1 >

    val2 < subnode2 > < / subnode2 >

    < / xmlnode >

    < xmlnode >

    val3 < subnode1 > < / subnode1 >

    < subnode2 > val4 < / subnode2 >

    < / xmlnode >

    (< / root > ') xml_to_update,.

    XmlType ("< a >

    < b > < /b > valb

    valc < c >/< c >

    < d >

    vald1 < d1 > < / d1 >

    < d2 > vald2 < / d2 >

    / < d: >

    Vale of < e > < /e >

    valf < f > < /f >

    < g >

    valg1 < g1 > < / g1 >

    valg2 < g2 > < / g2 >

    / < g >

    < h >

    valh1 < h1 > < / h1 >

    valh2 < h2 > < / h2 >

    < HR >

    (< /a > ') xml_to_extract_from

    the double)

    Select sd.xml_to_update,

    SD.xml_to_extract_from,

    insertXMLbefore (sd.xml_to_update,

    "/ root/xmlnode [1]."

    XmlType ("< extrainfo > ' |")

    "< b >" |

    ExtractValue (sd.xml_to_extract_from, ' / a/b / text () ').

    "< /b > < f >" |

    ExtractValue (sd.xml_to_extract_from, ' / a/f / text () ').

    ' / f <>|

    ((/ extrainfo > ')) updated_xml

    of sample_data sd;

    that worked, but I now need to add several other knots, I don't think that is the wisest way to continue to use. I tried Googling and forum searching but my search-fu must be low today, because I have not found similar examples that I can copy base my solution to. I'm sure that there is a funky way of doing it using xquery or something, but I admit not having a clue about where to start even with xquery!

    We are on 11.2.0.3, and the xmltype columns are stored as a CLOB (sorry Marco Gralike!).

    Can anyone help point me in the right direction please?

    Hello

    Using XQuery Update:

    SQL > with sample_data like)

    2 Select xmltype (')

    3

    4                        val1

    5                        val2

    6

    7

    8                        val3

    9                        val4

    10

    11 ') xml_to_update,.

    12 xmltype (')

    13                      valb

    14                      valc

    15

    16                        vald1

    17                        vald2

    18

    19                      vale

    20                      valf

    21

    22                        valg1

    23                        valg2

    24

    25

    26

    valh1

    27

    valh2

    28

    29 ") xml_to_extract_from"

    30 double

    31)

    32 select xmlserialize (document

    33 xmlquery)

    34 ' copy $d: = $old

    35 edit)

    36 Insert element extrainfo {} node

    $37 new/a/b

    38, $ new/a.

    39, $ new/e/f

    40, $/ a/h new

    41} as the first in $d / root

    42              )

    43 return $from

    44 from sd.xml_to_update as "old."

    45, sd.xml_to_extract_from as 'new '.

    46 by returning the content

    47           )

    dash 48

    49         )

    50 to sample_data sd;

    XMLSERIALIZE (DOCUMENTXMLQUERY)

    --------------------------------------------------------------------------------

    valb

    vald1

    vald2

    valf

    valh1

    valh2

    val1

    val2

    val3

    Val4

  • Read the column of XMLTYPE with Parent and several child nodes

    Hello

    I have an xmltype column which stores the data in the format below. There is possible that some of the parent node will have several child nodes. I'm not able to extract children nodes. Get the error as a value of type multiset... required singleton...
    I tried the sub query, but it returns only the records from parent with children nodes.

    < CrntRgstns >
    < CrntRgstn empStDt = '2000-08-21' Auth = 'ABCD' regCat = 'BM' u4FlngDt = '2011-05-12' stDt = '2011-11-08' st 'EMPTY' = actvReg = "N" updateTS = "2011-11 - 08T 00: 37:42" >
    < CrntDfcnys / >
    < / CrntRgstn >
    < CrntRgstn empStDt = '2000-08-21' Auth = 'ABCD' regCat = 'BM' u4FlngDt = '2012-01-13' stDt = '2012-01-13' st = 'DÉFICIENT' actvReg = 'Y' updateTS = "2012-01 - 13 T 18: 02:19" >
    < CrntDfcnys >
    < CrntDfcny dfcnyCd = "TEST" exmCd = "M10" createDt = "2012-01-13" / >
    < CrntDfcny dfcnyCd = "TEST" exmCd = "X 40" createDt = "2012-01-13" / >
    < / CrntDfcnys >
    < / CrntRgstn >
    < CrntRgstn empStDt = "2000-08-21" Auth = "XYZ" regCat = "SU" u4FlngDt = '2012-01-13' stDt = '2012-01-13' st = 'DÉFICIENT' actvReg = 'Y' updateTS = "2012-01 - 13 T 18: 02:19" >
    < CrntDfcnys >
    < CrntDfcny dfcnyCd = "TEST" exmCd = "M10" createDt = "2012-01-13" / >
    < CrntDfcny dfcnyCd = "TEST" exmCd = "X 40" createDt = "2012-01-13" / >
    < / CrntDfcnys >
    < / CrntRgstn >
    < / CrntRgstns >

    I tried to use 2 xmltable querys and using the child node of the xmltable 1 as input to xmltable 2. But it returns only the records that has child nodes. But I wanted all the records of CrntRgstn and if no child node CrntDfcnys so that also displays.

    Thank you
    Vinod K

    I tried to use 2 xmltable querys and using the child node of the xmltable 1 as input to xmltable 2. But it returns only the records that has child nodes.

    You're almost there, you just have to do an outer join:

    SQL> select x1.empStDt
      2       , x1.Auth
      3       , x1.regCat
      4       , x2.*
      5  from documents t
      6     , xmltable(
      7         '/CrntRgstns/CrntRgstn'
      8         passing t.xmldoc
      9         columns empStDt date         path '@empStDt'
     10               , Auth    varchar2(30) path '@Auth'
     11               , regCat  varchar2(2)  path '@regCat'
     12               , CrntDfcnys xmltype   path 'CrntDfcnys'
     13       ) (+) x1
     14     , xmltable(
     15         '/CrntDfcnys/CrntDfcny'
     16         passing x1.CrntDfcnys
     17         columns dfcnyCd  varchar2(30) path '@dfcnyCd'
     18               , exmCd    varchar2(3)  path '@exmCd'
     19               , createDt date         path '@createDt'
     20       ) (+) x2
     21  ;
    
    EMPSTDT     AUTH                           REGCAT DFCNYCD                        EXMCD CREATEDT
    ----------- ------------------------------ ------ ------------------------------ ----- -----------
    21/08/2000  ABCD                           BM
    21/08/2000  ABCD                           BM     EXAM                           M10   13/01/2012
    21/08/2000  ABCD                           BM     EXAM                           X40   13/01/2012
    21/08/2000  XYZ                            SU     EXAM                           M10   13/01/2012
    21/08/2000  XYZ                            SU     EXAM                           X40   13/01/2012
     
    

    Note: I have tested the above on 11.2.0.2 and it seems that there is a bug, if we add an outer join on the first XMLTable operator too.
    Normally, the first outer join is not necessary, in order to also test on your version without it.

  • Extraction of a node in an XMLtype table - selection of the previous query

    Hey all,.

    I work with a server Oracle 11 g r2 and basically need to be able to analyse and select nodes from it. I spent hours scouring the net and reading the manual oracle xml db trying to find an appropriate solution to my problem, but I can't seem to identify the correct way to do it. I have some experience in programming, but none with databases oracle, sql or xml in general so forgive me if this is a trivial question.

    OK, so the question:

    I have a very simple XML file saved under catalog.xml and it is as follows:

    <>Catalog
    < cd >
    < title > hide your heart < /title >
    < artist > Bonnie Tyler < / artist >
    < Country > UK < / country >
    < company > CBS Records < / company >
    < price > 9.90 < / price >
    < year > 1988 < / year >
    < CD >
    < cd >
    Empire Burlesque < title > < /title >
    < artist > Bob Dylan < / artist >
    < country > USA < / country >
    < company > Columbia < / company >
    < price > 10.90 < / price >
    < year > 1985 < / year >
    < CD >
    < / catalogue >

    Now, I want to be able to extract the title of the given cd a certain artist. So, for example, if the artist is "bob dylan", the title should be "empire burlesque".

    Now I created an XMLType table in Oracle as follows:

    CREATE BINARY XMLTYPE STORE AS XML BINARY XMLType TABLE.

    I then load my xml file into oracle by:

    Insert the BINARY values (XMLTYPE (BFILENAME ('XML_DIR', 'catalog.xml'), nls_charset_id ('AL32UTF8')));

    So far so good.

    Now for the part of the excerpt:

    First of all I've tried:

    SELECT extract (b.object_value, ' / catalogue/cd/title ')
    Binary b
    WHERE existsNode (b.object_value,'/catalog/cd [artist = "Bob Dylan"]') = 1;

    EXTRACT(B.OBJECT_VALUE,'/CATALOG/CD/TITLE')
    --------------------------------------------------------------------------------

    < title > hide your heart < /title >
    Burlesque Empire < title > < /title >

    1 selected line.



    It did not work because the xml file was all in 1 row then I realized that I had to split my xml in separate rows. Doing that, I had to convert the nodes < title > a virtual table using the functions XMLSequence() and table(). These functions convert nodes two title returned by the extract() function in a virtual table composed of two XMLType objects, each of which contains a single title element.

    Second test:

    SELECT value (d)
    Binary B,
    Table (xmlsequence(extract(b.object_value,'/catalog/cd'))) d
    WHERE existsNode (b.object_value,'/catalog/cd [artist = "Bob Dylan"]') = 1;

    VALUE (D)
    --------------------------------------------------------------------------------

    < cd >
    < title > hide your heart < /title >
    < artist > Bonnie Tyler < / artist >
    < Country > UK < / country >
    < company > CBS Records < / company >
    < price > 9.90 < / price >
    < year > 1988 < / year >
    < CD >

    < cd >
    Empire Burlesque < title > < /title >
    < artist > Bob Dylan < / artist >
    < country > USA < / country >
    < company > Columbia < / company >
    < price > 10.90 < / price >
    < year > 1985 < / year >
    < CD >

    2 selected lines.


    It's better because it is now divided into 2 different lines so I should be able to make a selection - where, and then select the title from the artist.

    However, this is where I have questions, I tried to literally hours but I can't understand how to use the results of the query above in my next. So I tried to use a suquery in this way:

    Select extract (sub1, ' cd/title')
    Of
    (
    SELECT value (d)
    Binary B,
    Table (xmlsequence(extract(b.object_value,'/catalog/cd'))) d
    ) sub1
    WHERE existsNode (sub1,'/ cd [artist = "Bob Dylan"]') = 1;

    However, sql * plus displays an error:

    ORA-00904: "SUB1": invalid identifier.

    I've tried dozens of variations to try to use subqueries but I simly can't do things.

    I heard you can do also do this using variables or pl/sql, but I don't know where to start.

    Any help would be greatly appreciated I tried everything at my disposal.

    This should help you get started!

    select banner as "Oracle version" from v$version where banner like 'Oracle%';
    
    create table otn5test(
      id number,
      data xmltype
    );
    
    insert into otn5test values (1, xmltype('
    
    Hide your heart
    Bonnie Tyler
    UK
    CBS Records
    9.90
    1988
    
    
    Empire Burlesque
    Bob Dylan
    USA
    Columbia
    10.90
    1985
    
    
    '));
    
    select otn5test.id, x.*
    from otn5test,
         xmltable('/catalog/cd[artist/text()="Bob Dylan"]' passing otn5test.data
         columns title varchar2(20) path 'title') x;
    
    select otn5test.id,
           xmlcast(xmlquery('/catalog/cd[artist/text()="Bob Dylan"]/title'
                   passing otn5test.data returning content)
           as varchar2(20)) from otn5test;
    
    drop table otn5test;
    
    sqlplus> @otn-5.sql
    
    Oracle version
    ------------------------------------------------------------------------------
    Oracle Database 11g Release 11.2.0.1.0 - 64bit Production
    
    Table created.
    
    1 row created.
    
         ID TITLE
    ---------- --------------------
          1 Empire Burlesque
    
         ID XMLCAST(XMLQUERY('/C
    ---------- --------------------
          1 Empire Burlesque
    
    Table dropped.
    
  • XMLTYPE extract some nodes

    Hello
    < book >
    < book >
    < id > 12 / < ID >
    Oracle < name > < / name >
    < / book >
    < book >
    < id > 15 / < ID >
    < name > net < / name >
    < / book >
    < / books >

    Please how can I retrieve the node containing the oracle book without the order of the element, in 10 g and 11 g

    I mean that the result should be

    < book >
    < id > 12 / < ID >
    Oracle < name > < / name >
    < / book >

    Thanks in advance

    How about using the EXTRACT with following XPath function? :
    book/books / [name = 'oracle']

    The whole sample test case:
    ------------------------------------------------------------
    CREATE TABLE testtab)
    ID NUMBER PRIMARY KEY,
    XML XMLTYPE
    );
    INSERT INTO testtab VALUES (1, XMLTYPE ('))

    12
    Oracle


    15
    NET

    '));
    COMMIT;

    SELECT EXTRACT (xml, '/ books/book [name = "oracle"]') FROM testtab;
    ------------------------------------------------------------

  • Update multiply nodes on the XMLType field

    Hi all.
    I have this table

    + 'DOCUMENT ' +.
    +(+
    + 'ID' NUMBER ENABLE NOT NULL, +.
    + 'ID_ARCHIVE' ENABLE NUMBER NOT NULL, +.
    + VARCHAR2 (20 BYTE) "USERNAME," +
    + DATE 'CREATION_DATE ', +.
    + DATE "LAST_UPDATE" +
    + VARCHAR2 (20 BYTE) "LAST_USERNAME," +
    + NUMBER OF 'VISIBLE ', +.
    + VARCHAR2 (20 BYTE) 'STATE ', +.
    + 'XML' 'SYS '. ("' XMLTYPE ',) +.


    It is an example of XML value:


    <? XML version = "1.0" encoding = "UTF-8"? >
    < root >
    < fields >
    < field fieldId = "text_141536485" = "true" type iterable = specifications 'text' = name of the 'simple' = value 'tiolo"="1"required ="false"status = 'ok' searchable ="true"="true"isIterate ="false"isField / > < field fieldId ="comp_1235813718"iterable ="true"type ="composite"specification ="composite"status = 'ok' searchable ="true"="true"isIterate ="false"isField >
    < fields >
    < field fieldId = "texte_-1661573009" iterables = "true" type = specifications 'text' = name of the 'simple' = 'New' value = "1" required = "false" status = 'ok' searchable = "true" = "true" isIterate = "false" isField / >»»
    < field fieldId = "texte_-1661573009" iterables = "true" type = specifications 'text' = name of the 'simple' = 'New' value = "2" required = "false" status = 'ok' searchable = "true" = "true" isIterate = "true" isField / >»»
    < / fields >
    < / field >
    < field fieldId = "comp_1235813718" = "false" isIterate = "true" type iterables = 'default' specification = 'default' status = 'ok' isField = "true" >
    < fields / >
    < / field >
    < / fields >
    < / root >


    I'd like to update the attribute name of all fields of Pentecost fieldId = "texte_-1661573009", that is to say, "meter".

    I have try this query:

    SELECT d.XML.extract('//field') in DOCUMENT d
    * where d.XML.existsNode ('/ / field [@fieldId = "texte_-1661573009"]') = 1; *


    It returns all fields with fieldId = "texte_-1661573009".

    The update:

    update the document overall. OBJECT_VALUE = d.XML.updateXML(OBJECT_VALUE,'//field/@fieldId','Counter')
    * where d.XML.existsNode (OBJECT_VALUE,'/ / field [@fieldId = "texte_-1661573009"]') = 1; *


    I get this error:

    SQL error: ORA-00904: "OBJECT_VALUE": invalid identifier
    * 00904. 00000 - "% s: invalid identifier."

    Could someone help me find the error?

    Thank you very much!

    Cristian

    Hello

    I have try this query:

    SELECT d.XML.extract('//field') in DOCUMENT d
    * where d.XML.existsNode ('/ / field [@fieldId = "texte_-1661573009"]') = 1; *

    It returns all fields with fieldId = "texte_-1661573009".

    In fact, it returns all the fields of a document where there is at least one field with fieldId "texte_-1661573009".
    It will make a difference with updateXML, because it does not update the nodes you expect.

    I get this error:

    SQL error: ORA-00904: "OBJECT_VALUE": invalid identifier
    00904, 00000 - '% s: invalid identifier '.

    OBJECT_VALUE is only used to refer to the column of a table of Type Object, such as an XMLType table.
    Here, you're dealing with an ordinary table, so use the appropriate column name, that is to say "XML".

    Do you want to:

    UPDATE document d
    SET d.xml = updateXML( d.xml,
                           '//field[@fieldId="text_-1661573009"]/@name',
                           'Counter' )
    WHERE d.xml.existsNode('//field[@fieldId="text_-1661573009"]') = 1
    ;
    

    ?

Maybe you are looking for