Update (transform) xmltype

It is a sequel to this discussion:

updateXML to null value

where it says towards the end:

Question 2. If there are any xml function which can update the name of the tag. as in the example above I need to change the < home_address > as < permanant_address >

No, not directly.

XQuery Update Facility, which is implemented in the 11.2.0.3 version, can do.

For lower versions, you will need to use XSLT or XQuery.

I, too, use 11.1 and I'd like to know how to turn an xmltype stored in a table using XSLT or XQuery. I would be grateful if someone could give an example of one or both.

Thank you

Morgan

4. so, I want to know how to do something like this (pseudocode);

update books

Set object_value =

XMLTRANSFORM (object_value, xsl)

where XMLExists ('/wrapper')

Is this possible?

What happens when you try?

Yes, it is possible:

SQL> var xsl clob
SQL>
SQL> begin
  2    :xsl := '
  3    
  4    
  5      
  6    
  7  ';
  8  end;
  9  /

PL/SQL procedure successfully completed.

SQL> update books
  2  set object_value =
  3      xmltransform(object_value, xmlparse(document :xsl))
  4  where xmlexists('/wrapper' passing object_value) ;

2 rows updated.

SQL> select count(*) from books where xmlexists('/book' passing object_value) ;

  COUNT(*)
----------
         4

Although I would not want to use XSLT in this specific example, XQuery is easier and better optimized:

SQL> roll
Rollback complete.
SQL>
SQL> update books
  2  set object_value =
  3      xmlquery(
  4        '/wrapper/book'
  5        passing object_value
  6        returning content
  7      )
  8  where xmlexists('/wrapper' passing object_value);

2 rows updated.

SQL> select count(*) from books where xmlexists('/book' passing object_value) ;

  COUNT(*)
----------
         4

Choose between XQuery and XSLT to transform an XML document really depends on the type of operations.

For example, I tend to use XSLT when processing needs of recursion, such as the removal of one space names default or delete/insert some nodes "deeply" in the document (if I can't use XQuery Update of course).

Tags: Database

Similar Questions

  • Transform XMLTYPE works differently in Oracle 10.1 and 11.2

    We are migrating our applications to Oracle 10.1 g to 11.2 g. We have a number of routines of PL/SQL that transform the incoming/outgoing XML using the XMLType Transform method. XSLT transformations that we use doesn't seem to work at 11.2. For example, the code below is a simplification of what we do. This code example uses the coded entrance to irreversibly and xslt to illustrate this point. The same code has very different results when operating in 10.1 and 11.2. In 10.1, the work of transformation. He was also using files in an xml tool. 11.2, none of the input XML is transformed. The only exit is the extra < sd:StandardBusinessDocument... which is hard-coded in the xslt as a wrapper.

    For example

    {code}

    declare

    out_sbd xmltype: = xmltype ("< OT_SBD_HEADER >

    < HEADER_VERSION > 1.0 < / HEADER_VERSION >

    SENDERS <>

    < OT_SENDER_RECEIVER >

    COGSD < ID > < / IDENTIFIER >

    < IDENTIFIER_AUTHORITY > urn:olgr.qld.gov.au:cogs < / IDENTIFIER_AUTHORITY >

    < / OT_SENDER_RECEIVER >

    < / SENDERS >

    <>RECEIVERS

    < OT_SENDER_RECEIVER >

    PORTAL of < ID > < / IDENTIFIER >

    < IDENTIFIER_AUTHORITY > urn:olgr.qld.gov.au: portal < / IDENTIFIER_AUTHORITY >

    < / OT_SENDER_RECEIVER >

    < / RECEIVERS >

    < DOCUMENT_INDENTIFICATION >

    urn:olgr.qld.gov.au < STANDARD > < / STANDARD >

    < TYPE_VERSION > 1.1 < / TYPE_VERSION >

    < INSTANCE_IDENTIFIER > c11ab0c6-22e7-4132-88f8-f81e88cde75c < / INSTANCE_IDENTIFIER >

    licenceInformation < TYPE > < / TYPE >

    < CREATION_DATE > 2012-05-30T 13: 55:41.167125 + 10:00 < / CREATION_DATE >

    < / DOCUMENT_INDENTIFICATION >

    < BUSINESS_SCOPE >

    < OT_SBD_HEADER_SCOPE >

    get < SCOPE_TYPE > < / SCOPE_TYPE >

    < SCOPE_INSTANCE_IDENTIFIER > GET_GAMING_STATISTICS_DATA < / SCOPE_INSTANCE_IDENTIFIER >

    < / OT_SBD_HEADER_SCOPE >

    < / BUSINESS_SCOPE >

    (< / OT_SBD_HEADER > ');

    --

    transformed_out_sbd xmltype.

    --

    sbd_header_out_xslt xmltype: = xmltype (' <? xml version = "1.0" encoding = "ISO-8859-1"? >)

    <!--

    This file was generated by Altova MapForce 2011r2sp1

    YOU MUST NOT CHANGE THIS FILE, BECAUSE IT WILL

    OVERWRITTEN WHEN YOU RE-RUN OF THE CODE GENERATION.

    See Altova MapForce Documentation for more details.

    http://www.Altova.com/MapForce

    ->

    " < xsl: stylesheet version ="1.0"xmlns: xsl = ' http://www.w3.org/1999/XSL/transform "" xmlns: XS = " " http://www.w3.org/2001/XMLSchema "exclude-result-prefixes ="xs"> "

    < xsl: output method = "xml" encoding = "UTF-8" Indent = "yes" / >

    < xsl: template match = "/" >

    " < sd:StandardBusinessDocument xsi: schemaLocation =" http://www.UNECE.org/CEFACT/namespaces/StandardBusinessDocumentHeader "' sbd.xsd ' xmlns:sd = ' http://www.UNECE.org/CEFACT/namespaces/StandardBusinessDocumentHeader "" xmlns: xsi = " " http://www.w3.org/2001/XMLSchema-instance ">

    < xsl: select = "* [local - name () = foreach & apos;" OT_SBD_HEADER & apos; and namespace - uri () = & apos; & apos;] ">

    < name of xsl: variable = "var1_DOCUMENTINDENTIFICATION" select = "* [local - name () = & apos;" DOCUMENT_INDENTIFICATION & apos; and namespace - uri () = & apos; & apos;] "/ >

    < name of xsl: variable = "var2_MANIFEST" select = "* [local - name () = & apos;" MANIFESTO & apos; and namespace - uri () = & apos; & apos;] "/ >

    < name of xsl: variable = "var3_resultof_cast" select = "string ($var1_DOCUMENTINDENTIFICATION / * [local - name () = & apos;)" MULTIPLE_TYPE & apos; and namespace - uri () = & apos; & ;]) "/ >

    < StandardBusinessDocumentHeader >

    < HeaderVersion >

    < xsl: value - of select = "string (HEADER_VERSION)" / >

    < / HeaderVersion >

    < xsl: for-each select = "SHIPPERS" >

    < name of xsl: variable = sΘlectionner "var4_OTSENDERRECEIVER" = "OT_SENDER_RECEIVER" / >

    sender <>

    <>identifier

    < xsl: attribute name = "Authority" >

    < xsl: value - of select = "string($var4_OTSENDERRECEIVER/IDENTIFIER_AUTHORITY)" / >

    < / xsl: attribute >

    < xsl: value - of select = "string($var4_OTSENDERRECEIVER/IDENTIFIER)" / >

    < / identifier >

    < / sender >

    < / xsl: foreach >

    < xsl: for-each select = 'RECEIVERS' >

    < name of xsl: variable = sΘlectionner "var5_OTSENDERRECEIVER" = "OT_SENDER_RECEIVER" / >

    < receiver >

    <>identifier

    < xsl: attribute name = "Authority" >

    < xsl: value - of select = "string($var5_OTSENDERRECEIVER/IDENTIFIER_AUTHORITY)" / >

    < / xsl: attribute >

    < xsl: value - of select = "string($var5_OTSENDERRECEIVER/IDENTIFIER)" / >

    < / identifier >

    < / receiver >

    < / xsl: foreach >

    < DocumentIdentification >

    < standard >

    < xsl: value - of select = "string($var1_DOCUMENTINDENTIFICATION/STANDARD)" / >

    < / standard >

    < TypeVersion >

    < xsl: value - of select = "string($var1_DOCUMENTINDENTIFICATION/TYPE_VERSION)" / >

    < / TypeVersion >

    < InstanceIdentifier >

    < xsl: value - of select = "string($var1_DOCUMENTINDENTIFICATION/INSTANCE_IDENTIFIER)" / >

    < / InstanceIdentifier >

    < type >

    < xsl: value - of select = "string($var1_DOCUMENTINDENTIFICATION/TYPE)" / >

    < / type >

    < MultipleType >

    < xsl: value-of select = "string (((normalize-space ($var3_resultof_cast) = & apos; true & apos ;) or (normalize-space ($var3_resultof_cast) = & apos; 1 & apos ;)))" / > ")))"

    < / MultipleType >

    < CreationDateAndTime >

    < xsl: value - of select = "string($var1_DOCUMENTINDENTIFICATION/CREATION_DATE)" / >

    < / CreationDateAndTime >

    < / DocumentIdentification >

    <>Manifesto

    < NumberOfItems >

    < xsl: value - of select = "string ((string($var2_MANIFEST/NUMBER_OF_ITEMS)))" / >

    < / NumberOfItems >

    < xsl: for-each select = "$var2_MANIFEST/MANIFEST_ITEMS" >

    < name of xsl: variable = sΘlectionner "var6_OTMANIFESTITEM" = "OT_MANIFEST_ITEM" / >

    < ManifestItem >

    < MimeTypeQualifierCode >

    < xsl: value - of select = "string($var6_OTMANIFESTITEM/MIME_TYPE)" / >

    < / MimeTypeQualifierCode >

    < UniformResourceIdentifier >

    < xsl: value - of select = "string($var6_OTMANIFESTITEM/RESOURCE_IDENTIFIER)" / >

    < / UniformResourceIdentifier >

    < description >

    < xsl: value - of select = "string($var6_OTMANIFESTITEM/DESCRIPTION)" / >

    < / description >

    < / ManifestItem >

    < / xsl: foreach >

    < / manifesto >

    < xsl: for-each select = "BUSINESS_SCOPE" >

    < name of xsl: variable = sΘlectionner "var7_OTSBDHEADERSCOPE" = "OT_SBD_HEADER_SCOPE" / >

    < BusinessScope >

    < scope >

    < type >

    < xsl: value - of select = "string($var7_OTSBDHEADERSCOPE/SCOPE_TYPE)" / >

    < / type >

    < InstanceIdentifier >

    < xsl: value - of select = "string($var7_OTSBDHEADERSCOPE/SCOPE_INSTANCE_IDENTIFIER)" / >

    < / InstanceIdentifier >

    <>identifier

    < xsl: value - of select = "string($var7_OTSBDHEADERSCOPE/SCOPE_IDENTIFIER)" / >

    < / identifier >

    < / scope >

    < / BusinessScope >

    < / xsl: foreach >

    < / StandardBusinessDocumentHeader >

    < / xsl: foreach >

    < / sd:StandardBusinessDocument >

    < / xsl: template >

    < / xsl: stylesheet >

    ');

    --

    --

    BEGIN

    transformed_out_sbd: = out_sbd.transform (sbd_header_out_xslt); -using the above hard coded XSLT to transform out_sbd

    --

    INSERT INTO z_clob_log (id, clob_name, clob_desc, clob_doc) - connect the output to a clob column in a table

    SELECT (select nvl (max (id), 0) + 1 _clob_log).

    TO_CHAR (sysdate, 'YYYYMMDD hh24:mi:ss') |' -CHANGED OUT_SBD',.

    transformed_out_sbd.getClobVal

    DOUBLE;

    COMMIT;

    END;

    {code}

    10.1, the output is as expected, the same thing that do the transformation using files in an xml tool.

    {code}

    " < sd:StandardBusinessDocument xsi: schemaLocation =" http://www.UNECE.org/CEFACT/namespaces/StandardBusinessDocumentHeader "' sbd.xsd ' xmlns:sd = ' http://www.UNECE.org/CEFACT/namespaces/StandardBusinessDocumentHeader "" xmlns: xsi = " " http://www.w3.org/2001/XMLSchema-instance ">

    < StandardBusinessDocumentHeader >

    < HeaderVersion > 1.0 < / HeaderVersion >

    sender <>

    < Authority = "identifier urn:olgr.qld.gov.au:cogs" > COGSD < / identifier >

    < / sender >

    < receiver >

    < Authority = "urn:olgr.qld.gov.au: portal identifier" > PORTAL < / identifier >

    < / receiver >

    < DocumentIdentification >

    urn:olgr.qld.gov.au < standard > < / Standard >

    < TypeVersion > 1.1 < / TypeVersion >

    < InstanceIdentifier > c11ab0c6-22e7-4132-88f8-f81e88cde75c < / InstanceIdentifier >

    licenceInformation < type > < / Type >

    < MultipleType > false < / MultipleType >

    < CreationDateAndTime > 2012-05-30T 13: 55:41.167125 + 10:00 < / CreationDateAndTime >

    < / DocumentIdentification >

    <>Manifesto

    < NumberOfItems / >

    < / manifesto >

    < BusinessScope >

    < scope >

    get < type > < / Type >

    < InstanceIdentifier > GET_GAMING_STATISTICS_DATA < / InstanceIdentifier >

    < identifier / >

    < / scope >

    < / BusinessScope >

    < / StandardBusinessDocumentHeader >

    < / sd:StandardBusinessDocument >

    {code}

    11.2, none of the original xml document is included in the output, only the < sd: StandardBusinessDocument... / >

    {code}

    " < sd:StandardBusinessDocument xsi: schemaLocation =" http://www.UNECE.org/CEFACT/namespaces/StandardBusinessDocumentHeader "' sbd.xsd ' xmlns:sd = ' http://www.UNECE.org/CEFACT/namespaces/StandardBusinessDocumentHeader "" xmlns: xsi = " " http://www.w3.org/2001/XMLSchema-instance "/>

    {code}

    The same happens using the SQL XMLTransform function, for example apply what follows with the above xml and xslt, except that it generates a separate closing tag < / sd:Standard... >

    Select xmltransform (out_sbd, sbd_header_out_xslt) in double transformed_out_sbd;

    Q: any ideas? Are there changes in 11g 11.2 requiring major changes to xslt?

    We have a lot of rewriting for this if we can't get this to work!

    Hi Eduardo,

    Report it as a bug to the Support of Oracle.

    The problem lies in the function namespace - uri (): comparison with an empty string is not resolved properly, so no node is still selected in the first xsl: for each.

    If you need a workaround solution, there are some that you can test:

    (1) if the entry documents are actually in no namespace (for example, in your example), delete all occurrences namespace - uri () of the style sheet.

    (2) in the opposite direction, you can give your document of entry a dummy namespace and now referenced in the style sheet. The namespace - uri () test will work in this case.

    (3) replace the occurrences of namespace - uri () by a somewhat more elaborate test that will handle namespace empty in particular, for example:

    (namespace-uri () = $nsuri or (not ($nsuri) and not (namespace - uri ()))

    Given that you work with generated style sheets, I understand that none of the options above are really satisfactory.

    If I had to work around the problem, I would probably go with the 2nd option which involves a smaller amount of refactoring.

  • update of XmlType?

    Hi all - I just have a quick question to do with the XMLTYPE columns.

    I have data similar to this:
    <ITEM name="TYPE">
      <NEW_VALUE>UT</NEW_VALUE>
    </ITEM>
    <ITEM name="XD_EOM_IND">
      <NEW_VALUE>Y</NEW_VALUE>
    </ITEM>
    <ITEM name="FID">
      <NEW_VALUE>A</NEW_VALUE>
    </ITEM>
    and I want to update the element names - i.e. I want to '= 'FID' ELEMENT name' as ELEMENT name = "DST_TYP", but I can't seem to find how to do a find in deca and replace as if the column was clear.

    is there something that I am missing?

    Hello

    Try the following:

    WITH t AS (
     SELECT xmltype('
    
      UT
    
    
      Y
    
    
      A
    
    ') doc
     FROM dual
    )
    SELECT updatexml(t.doc, '//ITEM[@name="FID"]/@name', 'DST_TYP')
    FROM t;
    

    The 2nd argument to the UPDATEXML is an XPath expression that selects all nodes (including attributes) to be updated.

  • How update the relational table with XML data?

    I get XML messages that include a bunch of data items to be updated in a table. An arbitrary subset of rows is updated for each message received.

    The output of the following example is correct, but the use of the intermediate table that bothers me. The temporary table can be eliminated somehow? Or is the most reasonable way to loop just explicitly and parse the XML message and then update each row separately?

    I'm under 11.2.0.1.0.
    create table otn9test (
      id number not null primary key,
      data xmltype
    );
    
    insert into otn9test values (1, xmltype('<data>default for 1</data>'));
    insert into otn9test values (2, xmltype('<data>default for 2</data>'));
    insert into otn9test values (3, xmltype('<data>default for 3</data>'));
    
    create table otn9input (
      id number,
      data xmltype
    );
    
    column data format a30
    
    declare
      updata constant xmltype := xmltype('<root>
      <item>
        <id>1</id>
        <data>Id 1 updated.</data>
      </item>
      <item>
        <id>3</id>
        <data>Id 3 updated.</data>
      </item>
      <item>
        <id>4</id>
        <data>Id 4 updated.</data>
      </item>
    </root>');
    
    begin
      insert into otn9input
        select * from
        xmltable('/root/item' passing updata
              columns
              id number path 'id',
              data xmltype path 'data');
    
      update otn9test t set data = (
        select data from otn9input i
        where t.id = i.id
      ) where t.id in (select id from otn9input);
    
      commit;
    end;
    /
    
    select * from otn9input;
    
    /*
         ID DATA
    ---------- ------------------------------
          1 <data>Id 1 updated.</data>
          3 <data>Id 3 updated.</data>
          4 <data>Id 4 updated.</data>
    */
    
    select * from otn9test;
    
    /*
         ID DATA
    ---------- ------------------------------
          1 <data>Id 1 updated.</data>
          2 <data>default for 2</data>
          3 <data>Id 3 updated.</data>
    */
    
    drop table otn9input;
    drop table otn9test;

    The temporary table can be eliminated somehow?

    You can do it with the MERGER:

    merge into otn9test t
    using (
      select id, data
      from xmltable('/root/item' passing updata
            columns
              id   number  path 'id',
              data xmltype path 'data'
           )
    ) x
    on ( t.id = x.id )
    when matched then update
     set t.data = x.data
    ;
    

    However, if you are looking for performance on large data sets, I think that the best is to use an intermediate table of XMLType (binary storage) to maintain the XML instance.

    create table otn9input of xmltype
    xmltype store as securefile binary xml;
    
    insert into otn9input values(
    xmltype('
      
        1
        Id 1 updated.
      
      
        3
        Id 3 updated.
      
      
        4
        Id 4 updated.
      
    ')
    );
    
    merge into otn9test t
    using (
    select id, data
    from otn9input,
         xmltable('/root/item' passing object_value
              columns
                id number path 'id',
                data xmltype path 'data'
         )
    ) x
    on ( t.id = x.id )
    when matched then update
     set t.data = x.data
    ;
    

    A structured XMLIndex could also help.

  • Move a node in an XML (Jdev 11.1.1)

    Hi all
    I'm writing a query to move a node within a XML.

    For example, of:
    < root >
    < fields >
    < field id = "1" >... < / field >
    < field id = "2" >... < / field >
    < field id = "3" >... < / field >
    < field id = "4" >... < / field >
    * < field id = "5" >... < / field > *.
    < / fields >
    < / root >

    TO:
    < root >
    < fields >
    < field id = "1" >... < / field >
    * < field id = "5" >... < / field > *.
    < field id = "2" >... < / field >
    < field id = "3" >... < / field >
    < field id = "4" >... < / field >
    < / fields >
    < / root >

    I can do it in 3 steps:
    1 exctractnode +//field[@id="5"]+ for recovery < field id = "5" >... < / field >
    2 deleteXML for the +//field[@id="5"]+ node
    3 insertXMLBefore +//field[@id="2"]+


    Is it possible to do in 1 single step and for several overseas departments? (I need to do it in java)

    Thank you
    Cristian

    Published by: on February 3, 2011 baol 5.53

    And wouldn't be a real UPDATE on XMLTYPE fileld XML on my Document table.

    Then do a UPDATE :)

     SQL> create table document (
      2   doc_id number,
      3   xml    xmltype
      4  );
    
    Table created
    
    SQL> insert into document values(1,
      2  xmltype('
      3    
      4      F1
      5      F2
      6      F3
      7      F4
      8      F5
      9    
     10  ')
     11  );
    
    1 row inserted
    
    SQL> update document d
      2  set d.xml =
      3         insertXMLBefore(
      4           deleteXML(
      5             d.xml,
      6             '//field[@id="5"]'
      7           ),
      8           '//field[@id="2"]',
      9           XMLQuery('$d//field[@id="5"]' passing d.xml as "d" returning content)
     10         )
     11  where d.doc_id = 1
     12  ;
    
    1 row updated
    
    SQL> set long 10000
    SQL> select xmlserialize(document xml as clob indent) from document;
    
    XMLSERIALIZE(DOCUMENTXMLASCLOB
    --------------------------------------------------------------------------------
    
      
        F1
        F5
        F2
        F3
        F4
      
    
     
    

    And since you are working with java, do not forget to use bind variables to execute the statement.
    Something like (not tested):

    update document d
    set d.xml =
           insertXMLBefore(
             deleteXML(
               d.xml,
               '//field[@id="'|| ? ||'"]'
             ),
             '//field[@id="'|| ? ||'"]',
             XMLQuery('$d//field[@id=$ID]'
               passing d.xml as "d",
                       ? as "ID"
               returning content
             )
           )
    where d.doc_id = 1
    ;
    
  • Adding namespace to the XML output

    Hello

    I have a requirement to generate an XML document for the columns in the table. I use DBMS_XMLgen.getXML inside my procedure to get the XML document.

    The result I get after my procedure is:

    <? XML version = "1.0"? >
    < EMP >
    < EMPLOYEE_NO > 000017 < / EMPLOYEE_NO >
    ASSETS of < EMPLOYEE_STATUS > < / EMPLOYEE_STATUS >
    Mini < NAME_LAST > < / NAME_LAST >
    < NAME_FIRST / >
    < / EMP >

    But I also need to prefix and uri of namespace in the xml output. Is it possible to add the prefix and namespace uri to the xml output.

    So what I need, is something like below one:

    <? XML version = "1.0"? >
    < xs:EMP > xmlns: out = "http://xmlns:out="http:/example.org/ver1.0/ThisISTest#">
    < xs:EMPLOYEE_NO > 000017 < / xs:EMPLOYEE_NO >
    ACTIVE < xs:EMPLOYEE_STATUS > < / xs:EMPLOYEE_STATUS >
    Mini < xs:NAME_LAST > < / xs:NAME_LAST >
    < xs:NAME_FIRST / >
    < / xs:EMP >


    Any solutions or examples of code on it would be a great help.

    Thanks in advance.

    Strange...

    OK, back to the basics:

    What is your version of db (all four digits please)?

    The following gives the expected result?

    select xmltype('
    
    000017
    ACTIVE
    Mini
    
    ').transform(
     xmltype(
    '
    
    
    
    
    
    
    '
     )
    ).getClobVal()
    from dual;
    
  • Rename "Column" of output when using XMLCOLATTVAL

    Hello

    Can someone please help me to replace the word "Column" in the output to something else when you use XMLCOLATTVAL. For example, in the output for the following statement, I would like to see 'Field' instead of 'column '.

    I'm on 10g R2.

    SELECT XMLELEMENT ("Emp",
    XMLCOLATTVAL (e.employee_id, select, e.salary)) 'item Emp.
    E EMPLOYEES
    WHERE employee_id = 204;

    Emp element
    --------------------------------------------------------------------
    < Emp >
    < column name = "Employe_id" > 204 < / column >
    < column name = "Name" > Baer < / column >
    < column name = "SALARY" > 10000 < / column >
    < / Emp >


    Any help is greatly appreciated.

    Thank you
    Suresh

    Hello

    No 'simple' solution, but you can try one of them, according to your needs:

    (1) apply an XSL transformation to the output

    SELECT XMLElement(
     "Emp", XMLColattval(e.employee_id, e.last_name, e.salary)
    )
    .transform(
     xmltype(
    '
    
    
      
    
    
      
        
      
    
    
      
        
      
    
    '
     )
    )
    FROM hr.employees e
    WHERE employee_id = 204;
    

    (2) "XQuerying" (as an alternative to XSLT)

    SELECT XMLElement("Emp",
      XMLQuery(
       'for $i in /*
        return element Field {
          attribute name {$i/name()},
          $i/text()
        }'
       passing XMLForest(e.employee_id, e.last_name, e.salary)
       returning content
      )
    )
    FROM hr.employees e
    WHERE employee_id = 204;
    

    (3) or, of course, generating the correct structure in the first place

    SELECT XMLElement(
     "Emp",
     XMLElement("Field", xmlattributes('EMPLOYEE_ID' as "name"), e.employee_id),
     XMLElement("Field", xmlattributes('LAST_NAME' as "name"), e.last_name),
     XMLElement("Field", xmlattributes('SALARY' as "name"), e.salary)
    )
    FROM hr.employees e
    WHERE employee_id = 204;
    
  • XMLDOM.writetoclob hung forever when you write a domnode in a temporary clob

    Hello

    Wondering has anyone encountered anything similar (or know a work-around)

    1. basically an XML file load procedure below. (OK)
    2 removes the reference to the external dtd, Ref was catchy and error (OK)
    3 analysis the XML (OK)
    4 Gets a list of the 'question' tags (OK) - should be up to 500 elements item in XML
    5 loops on all items
    a. written node for temp clob *(PROBLEM HERE) *.
    b. creates clob xmltype (OK)
    c. transforms xmltype and assigns to an another xmltype (OK)
    d. Insert new xmltype (OK)

    This procedure is used by a java os threaded application to load thousands of files to db.

    It works very well 99% of the time, but for some files, the procedure is suspended to (5.a: write domnode clob using xmldom.writetoclob)

    I am absolutely sure that the problem is due to the characters of the domnode as all files that have hanging on the treatment contain these weird characters
    the db character set is Unicode AL32UTF8, he should be able to handle almost anything, saying that if it is a prob with the characters so why do
    the loadclobfromfile procedure succeed.

    Developed on the database on Oracle 11 g Enterprise Edition Release 11.2.0.1.0 - 64 bit

    I have no prob rejecting the node and continue the treatment but is blocked just procedure and I have to kill the thread on the operating system.

    Is there a way of

    1. test for invalid AL32UTF8 tanks and jump error.
    or
    2 circumvent the process of xmldom.writetoclob and create an xmltype of the xmldom.domnode (I tried to convert domnode-> domdocument-> xmltype, no joy)
    or
    Open to suggestions


    PROCEDURE
    ---------------------------------------------------------------------------------------------------------------
    PROCEDURE process_blog_xml_file (
          p_file_name     IN   VARCHAR2,
          p_insert_date   IN   VARCHAR2,
          p_dir           IN   VARCHAR2 DEFAULT NULL
       )
       IS
          newsurl        VARCHAR2 (80);
          parser         xmlparser.parser;
          newsxml        xmldom.domdocument;
          titles         xmldom.domnodelist;
          titles_found   NUMBER;
          curnode        xmldom.domnode;
          textchild      xmldom.domnode;
          dest_clob      CLOB;
          l_temp_clob    CLOB;
          src_clob       BFILE         := BFILENAME (g_zip_file_dir, p_file_name);
          dst_offset     NUMBER             := 1;
          src_offset     NUMBER             := 1;
          lang_ctx       NUMBER             := DBMS_LOB.default_lang_ctx;
          warning        NUMBER;
          l_xml          XMLTYPE;
          xsldata        XMLTYPE;
          xmldata        XMLTYPE;
          l_dir          VARCHAR2 (1000);
       BEGIN
          LOG (   'Start Processing file '
               || p_file_name
               || ' from zip '
               || p_insert_date
              );
    
          IF p_dir IS NULL
          THEN
             SELECT directory_path
               INTO l_dir
               FROM all_directories
              WHERE directory_name = g_zip_file_dir;
          ELSE
             l_dir := p_dir;
          END IF;
    
          IF g_xsl_clob IS NULL
          THEN
             init_xsl_clob;
          END IF;
    
          com_polecat_xmldb_utils.set_load_date
                                      (TO_DATE (REPLACE (REPLACE (p_insert_date,
                                                                  '_',
                                                                  '-'
                                                                 ),
                                                         '.zip',
                                                         ''
                                                        ),
                                                'DD-MM-YYYY'
                                               )
                                      );
          LOG ('ITEM.Loaddate set : ' || com_polecat_xmldb_utils.get_load_date);
          xsldata := XMLTYPE.createxml (g_xsl_clob);
          LOG ('Read xsl file to clob');
          DBMS_LOB.OPEN (src_clob, DBMS_LOB.lob_readonly);
          DBMS_LOB.createtemporary (dest_clob, TRUE);
          DBMS_LOB.loadclobfromfile (dest_lob          => dest_clob,
                                     src_bfile         => src_clob,
                                     amount            => DBMS_LOB.getlength
                                                                         (src_clob),
                                     dest_offset       => dst_offset,
                                     src_offset        => src_offset,
                                     bfile_csid        => NLS_CHARSET_ID
                                                                       ('AL32UTF8'),
                                     lang_context      => lang_ctx,
                                     warning           => warning
                                    );
          LOG ('Read xml file to clob');
          DBMS_LOB.CLOSE (src_clob);
          parser := xmlparser.newparser;
          dest_clob := REPLACE (dest_clob, g_blog_dtd_remove, '');
          LOG ('Parse xml ');
          xmlparser.parseclob (parser, dest_clob);
          DBMS_LOB.freetemporary (dest_clob);
          newsxml := xmlparser.getdocument (parser);
          xmlparser.freeparser (parser);
          titles := xmldom.getelementsbytagname (newsxml, 'item');
          LOG ('Load  blogs items to ITEM table. ');
    
          FOR j IN 1 .. xmldom.getlength (titles)
          LOOP
             curnode := xmldom.item (titles, j - 1);
             DBMS_LOB.freetemporary (l_temp_clob);
             DBMS_LOB.createtemporary (l_temp_clob, TRUE);
             LOG ('write node to temp clob ' || j);
             xmldom.writetoclob (curnode, l_temp_clob);                                              <-- Hanging Here
             LOG ('create xml type from clob ' || j);
             l_xml := XMLTYPE.createxml (l_temp_clob);
             LOG ('apply xsl transform to xml ' || j);
             xmldata := l_xml.transform (xsldata);
             LOG ('Insert to item table  ' || j);
    
             BEGIN
                INSERT INTO item
                     VALUES (xmldata);
             EXCEPTION
                WHEN OTHERS
                THEN
                   LOG ('Error::  ' || SQLERRM);
             END;
    
          END LOOP;
    
          xmldom.freedocument (newsxml);
          LOG (   'Finished Processing file '
               || p_file_name
               || ' from zip '
               || p_insert_date
              );
       EXCEPTION
          WHEN OTHERS
          THEN
             LOG (SQLERRM);
       END;
    Note variables starting with g_ are defined in package specifications

    See you soon

    Ian

    Published by: user3604054 on April 1st, 2010 06:52

    Published by: user3604054 on April 1st, 2010 14:57

    Published by: user3604054 on April 1st, 2010 15:00

    Published by: user3604054 on April 1st, 2010 15:00

    Published by: user3604054 on April 1st, 2010 15:05

    Published by: user3604054 on April 1st, 2010 15:06

    Why not go to a CLOB in an XMLTYPE via
    l_xml: = XMLType (dest_clob);
    and then analyze the XMLType in PL/SQL, as shown in my example of method 2 in {message identifier: = 3610259}. If you leave off of the. text() and the. getStringVal() then the .extract returns an XMLType in order to use your call .transform.

    Easier for me then attempt to analyze a DOMDocument for data. I did both and prefer the XMLType road.

  • List implied when you use the instance of an object TABLE.

    I've been looking for a solution to this problem, but nothing helped.
    I have an XML schema that specifies in the root element:
    < xsd: element name = "onestring" type = "xs: String" minOccurs = "1" maxOccurs = "1" / >
    < xsd: element name = "manystrings" type = "xs: String" minOccurs = "1" maxOccurs = "unbounded" / >

    So I created a few types in my database:
    CREATE OR REPLACE TYPE VARCHAR_TABLE AS VARCHAR TABLE (5);
    /

    CREATE or REPLACE TYPE rootelement AS OBJECT)
    onestring varchar (5),
    manystrings VARCHAR_TABLE
    )
    /

    Now, I do the following:
    DECLARE
    XML XMLTYPE.
    obj rootelement;
    BEGIN
    obj: = rootelement ("valA", VARCHAR_TABLE ('val1', 'val2', 'val3'));
    XML: = XMLTYPE (obj);
    print_out (xml.getstringval);
    END;
    /

    And on this basis, the result I get is:
    < ROOTELEMENT >
    valA < ONESTRING > < / ONESTRING >
    < MANYSTRINGS >
    val1 < VARCHAR2 > < / VARCHAR2 >
    val2 < VARCHAR2 > < / VARCHAR2 >
    val3 < VARCHAR2 > < / VARCHAR2 >
    < / MANYSTRINGS >
    < / ROOTELEMENT >

    When I want to see is:
    < ROOTELEMENT >
    valA < ONESTRING > < / ONESTRING >
    val1 < MANYSTRINGS > < / MANYSTRINGS >
    val2 < MANYSTRINGS > < / MANYSTRINGS >
    val3 < MANYSTRINGS > < / MANYSTRINGS >
    < / ROOTELEMENT >

    This can be accomplished? I also need the output XML to be read back in. (currently I call XMLTYPE (xml) .toObject (obj);).

    Thanks in advance.

    Dave

    Well, since the XSL Transformations worked at 10.1 too, what follows will do what you want

    SELECT XMLTYPE(ROOTELEMENT('valA', VARCHAR_TABLE('val1', 'val2', 'val3'))).TRANSFORM(XMLTYPE('
    
        
    
        
            
                
                    
                
                
                    
                
            
        
    
        
            
                
           
            
        
    
        
            
                
            
        
    
    
    ')) AS TRANSFORMED
      FROM DUAL
    

    Sorry for a previous solution that would not apply to your version, but I struggle to remember the characteristics of each of them separate. I remembered vaguely (I work with 11g for a bit now) that APPENDCHILDXML was the 10g feature, but does not remember that it was in fact 10.2.

    Concerning

    Philippe

  • SOS! a difficult problem to extract XML.

    I have a table like this xmltype:
    SQL > select object_value in the tbl_testxml;
    < member >
    < name of grandfather = 'Tom' age '66' = >
    < father name = 'John' age '46' = >
    < name son = "Simon" age = "20" / >
    < name son = "Steve" age = "19" / >
    < / father >
    < name father = "Jeff" age = "45" >
    < name son = "Mark" age = "17" / >
    < name son = "Matthew" age = "15" / >
    < / father >
    < / grandfather >
    < / members >

    I want to do is extract the grandfather, father and son's name (on the same line if they are in the same family), so I use this sql query:

    Select extract (value (v_xml), '//grandfather/ @name'): the grandfather,.
    Extract (value (v_xml), '//Grandfather/Father/ @name') as the father.
    Extract (value (v_xml), '//Grandfather/Father/son/ @name') son
    of tbl_testxml t.
    TABLE (XMLSEQUENCE (EXTRACT (t.object_value, ' / members))) v_xml;

    The output is finally like this:
    grandfather                              father                                  son
    ========                                 ==============                          ================
    Tom                                       JohnJeff                               SimonSteveMarkMathiew
    But this isn't what I want, what I want is like this:
    grandfather          father         son
    ========             ======         ======
    Tom                   John           Simon
    Tom                   John           Steve
    Tom                   Jeff            Mark
    Tom                   Jeff            Mathiew
    is it possible to get the above result?

    I tried xmlquery xmltable etc., none of them works :(

    Thank you very much!

    Published by: user3318788 on July 10, 2009 17:14

    Published by: user3318788 on July 11, 2009 17:23

    Published by: user3318788 on July 11, 2009 17:29

    Certainly not ideal, but you can transform the original XML using XSL so that it better fits your requirement:

    SELECT extractvalue(v_xml.column_value,'//grandfather') as grandfather,
           extractvalue(v_xml.column_value,'//father') as father,
           extractvalue(v_xml.column_value,'//son') as son
    FROM tbl_testxml t,
    TABLE(
     XMLSEQUENCE(
      EXTRACT(t.object_value.transform(
              xmltype('
              
              
              
               
                
                 
                 
                 
                
               
              
              
              ')
              ), '//branch'
      )
     )
    ) v_xml;
    

    Basically, the XSL language takes each sheet (IE each son), retrieves his ancestors and presents them in separate items of BRANCH.
    The SQL query then just extract all nodes branch with XMLSEQUENCE (XMLTABLE works as well) and again from each Member in a separate column.

  • Since the update to 14.0.1 javascript error appeared (this.transforms is not defined - 3-4 errors per second)

    Our phone system of companies has a web interface since the 14.0.1 update is no longer works. I tried to open it in safe mode with no extension active and ensure that cache has been cleared. In the error logs, I see "this.transforms is undefined" and is repeated 3 - 4 times per second, no matter how long the page is opened. Many pages in the web interface are compressed and if I select a different tab background change but not the areas that fall within her and all submit buttons are ignored.

    It works in other browsers and in older versions of firefox, so our miracle temp to say personal use Chrome until we have a chance to roll back on Firefox, even if we are not sure if Firefox is simply updating again.

    Finally solved the problem. Discovered that the issue was only happening on HP systems so that it narrowed down. Yet a new windows install using their disks restore would fail on the new update (but only if HP utilities were all re-installed - for example, as fingerprint reader security utilities). I got some new updates for those and the problems went away. Yippee. My guess is that it was the security utilities that run in the background, because they are not browser so plugins work even in SafeMode to browser.

    Glad we got going I didn't leave Firefox. What a pain though, as he had really left me speechless.

  • How can I remove J2SE Runtime Environment 5.0 update 11. Application of transformation error when you use Add/Remove programs

    Cannot remove J2SE Runtime Environment 5.0 update 11 or Java or Java 2 Runtime Environment SEv1.4.2_6.

    Add/Remove Programs DOES NOT WORK.  Message received when you try to remove programs is, "error application of transformations".

    Java (TM) 6 Update 21 is installed on my computer.

    Please let know us the step by step procedure to remove the old Java programs.  Thank you.

    E-mail address is removed from the privacy *.

    use revo uninstaller

  • What is the list of updates that are needed to transform to SP3?

    What is the list of these KB upgrades that are needed to transform to Service Pack 3. I want to install them manually.
    I currently have:
    KB942288
    KB940157

    And want the whole list. If you don't know then you can go to: Control Panel > Add / Remove Programs if you are on the Service Pack 3 update...

    To 'turn' to SP 3, you must actually install SP3. There is no list that "transforms".

  • No tab transformation of lightroom after update.

    I've just updated to the latest version of lightroom cc and I still don't have a transformation on the side Panel tab. I am a photographer of architecture, so I was happy using the guided vertical feature. Any guidance would be greatly appreciated!

    El capitan, like all the latest versions of Mac OS X number is 64-bit only, so it must be. You just need to install Lightroom CC creative cloud app. Then, you will also need to make sure to start the right program. Installation of LR CC removes the old enough now LR 5.7.1 and the icon in your dock will still refer to the old version in your Applications folder. You can open LR CC of the PPA for CC and then control click (or right-click) on the new icon for Lightroom that bounces in your dock and select "keep in dock" If you have a shortcut in your dock that is easy to find. You can get rid of the icon in your dock for LR 5 after that.

  • Update of the data in the Table using XMLTYPE DATA

    I did insertions using XMLTYPE data but have never done it and update. Can someone give me some advice?

    PROCEDURE ADD_LABORDER_CODES)

    IN_ORDERCODESXML IN CLOB DEFAULT NULL,

    Number of OUT OUT_AFFECTEDROWS

    )

    AS

    X SYS. XMLTYPE;

    BEGIN

    X: = SYS. XMLTYPE. CREATEXML (IN_ORDERCODESXML);

    INSERT INTO MAINT_LABORD_CODES)

    INSERT INTO MAINT_LABORD_CODES)

    LABORD_CODE_ID,

    COMPENDIUM_ID,

    ORDER_CODE,

    ORDER_DESC,

    ACTIVE,

    TIMESTAMP,

    MODIFIED_BY)

    SELECT MLOCDS_SEQ. NEXTVAL,

    EXTRACTVALUE (VALUE (MLOC), '/ ORDERCODE/COMPENDIUM_ID') AS COMPENDIUM_ID,

    EXTRACTVALUE (VALUE (MLOC), '/ ORDERCODE/ORDER_CODE') AS ORDER_CODE,

    EXTRACTVALUE (VALUE (MLOC), '/ ORDERCODE/ORDER_DESC') AS ORDER_DESC,.

    EXTRACTVALUE (VALUE (MLOC), '/ ORDERCODE/LOINC_CODE') AS LOINC_CODE,

    EXTRACTVALUE (VALUE (MLOC), '/ ORDERCODE/ACTIVE') AS ACTIVE.

    EXTRACTVALUE (VALUE (MLOC), '/ ORDERCODE/TIMESTAMP') AS TIMESTAMP.

    EXTRACTVALUE (VALUE (MLOC), '/ ORDERCODE/MODIFIED_BY') AS MODIFIED_BY

    TABLE (XMLSEQUENCE (EXTRACT(X,'/ORDERCODES/ORDERCODE'))) NMCO;

    OUT_AFFECTEDROWS: = NUMBER OF ROWS SQL %;

    EXCEPTION

    WHILE OTHERS THEN

    dbms_output.put_line (SQLERRM);

    RAISE_APPLICATION_ERROR (-20001, SQLERRM);

    END;

    Example of use of the FUSION-

    If the line exists in the target table (based on the COMPENDIUM_ID and ORDER_CODE values), the UPDATE is, if not to INSERT:

    declare
    
      in_ordercodesxml  clob :=
      '
      
        500
        696231
        ABO Group & Rh Type
        NULL
        12345
        Y
        2014-08-13
        1
      
    ';
    
    begin
    
      merge into maint_labord_codes t
      using (
        select compendium_id
             , order_code
             , order_desc
             , loinc_code
             , active
             , timestamp
             , modified_by
        from xmltable('/ORDERCODES/ORDERCODE'
               passing xmltype(in_ordercodesxml)
               columns COMPENDIUM_ID    number(10)    path 'COMPENDIUM_ID'
                     , ORDER_CODE       varchar2(50)  path 'ORDER_CODE'
                     , ORDER_DESC       varchar2(250) path 'ORDER_DESC'
                     , LOINC_CODE       varchar2(10)  path 'LOINC_CODE'
                     , ACTIVE           varchar2(1)   path 'ACTIVE'
                     , TIMESTAMP        date          path 'TIMESTAMP'
                     , MODIFIED_BY      number(10)    path 'MODIFIED_BY'
             )
      ) x
      on (     t.compendium_id = x.compendium_id
           and t.order_code = x.order_code )
      when matched then update
        set t.order_desc = x.order_desc
          , t.loinc_code = x.loinc_code
          , t.active     = x.active
          , t.timestamp  = x.timestamp
          , t.modified_by = x.modified_by
      when not matched then insert
      (
        labord_code_id
      , compendium_id
      , order_code
      , order_desc
      , loinc_code
      , active
      , timestamp
      , modified_by
      )
      values (
        mlocds_seq.nextval
      , x.compendium_id
      , x.order_code
      , x.order_desc
      , x.loinc_code
      , x.active
      , x.timestamp
      , x.modified_by
      );
    
    end;
    /
    

    Also note that I used XMLTABLE instead of TABLE/XMLSEQUENCE, which is much easier to use (and not deprecated in the latest versions).

    You have not precisely the date format in the TIMESTAMP element so I assumed a conform to W3C.

    If you have a problem with this part, return to a projection of VARCHAR2 and use TO_DATE with actual size.

Maybe you are looking for