UPDATEXML

Hello
My conf :
SQL> select * from V$VERSION;
BANNER
Oracle Database 11g Express Edition Release 11.2.0.2.0 - Beta
PL/SQL Release 11.2.0.2.0 - Beta
CORE 11.2.0.2.0 Production
TNS for 32-bit Windows: Version 11.2.0.2.0 - Beta
NLSRTL Version 11.2.0.2.0 - Production
One of my XML stored document :
SQL> SELECT v.OBJECT_VALUE
2 FROM vol_reel_xml_2 v
3 WHERE XMLEXISTS('$obj/vol_reel[@nvol="AF6154"]'
4 PASSING v.OBJECT_VALUE AS "obj")
5 AND XMLEXISTS('$obj/vol_reel/passagers/pax[@num_carte=13457934]'
6 PASSING v.OBJECT_VALUE AS "obj")
7 AND TO_DATE(XMLCAST(
8 XMLQUERY('$obj/vol_reel/@datev'
9 PASSING BY VALUE v.OBJECT_VALUE AS "obj"
10 RETURNING CONTENT)
11 AS VARCHAR2(12)),'YYYY-MM-DD')
12 = TO_DATE('2012-08-31','YYYY-MM-DD');
OBJECT_VALUE
<?xml version="1.0" encoding="WINDOWS-1252"?>
<vol_reel nvol="AF6154" datev="2012-08-31">
<passagers>
<pax num_carte="13457934">
<nom>Lacombe</nom>
<prenom>Serge</prenom>
<siege>05A</siege>
<prix>190</prix>
</pax>
<pax num_carte="44482340">
<nom>Blanchet</nom>
<prenom>Agnes</prenom>
<siege>17D</siege>
<prix>146</prix>
</pax>
</passagers>
</vol_reel>
I want update the "prix" element for the first pax (198 replace 190) :
With the same predicates, the element isn't updated :
SQL> UPDATE vol_reel_xml_2 v
2 SET v.OBJECT_VALUE =
3 UPDATEXML(v.OBJECT_VALUE,'/vol_reel/passagers/pax/prix/text()','198')
4 WHERE XMLEXISTS('$obj/vol_reel[@nvol="AF6154"]' PASSING v.OBJECT_VALUE AS "obj")
5 AND XMLEXISTS('$obj/vol_reel/passagers/pax[@num_carte=13457934]'
6 PASSING v.OBJECT_VALUE AS "obj")
7 AND TO_DATE(XMLCAST(
8 XMLQUERY('$obj/vol_reel/@datev'
9 PASSING BY VALUE v.OBJECT_VALUE AS "obj"
10 RETURNING CONTENT)
11 AS VARCHAR2(12)),'YYYY-MM-DD')
12 = TO_DATE('2012-08-31','YYYY-MM-DD');
0 rows updated.
Any idea?
Thanks in advance

Thanks
You're right, my table is created based on XML Schema :
CREATE TABLE vol_reel_xml_2 OF XMLType
XMLTYPE STORE AS OBJECT RELATIONAL
XMLSCHEMA "http://www.iut-blagnac.fr/vols.xsd"
ELEMENT "vol_reel"
VARRAY "XMLDATA"."passagers"."pax" STORE AS TABLE pax_tabnt;
---xml schema (vol_reel_annote.xsd)
<?xml version="1.0" encoding="utf-8"?>
<xsd:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xdb:storeVarrayAsTable="true" version="1.0" xmlns:xdb="http://xmlns.oracle.com/xdb" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
     <xsd:element name="vol_reel" type="vol_reelType"/>
     <xsd:complexType name="vol_reelType" xdb:SQLType="VOL_REEL_XML_T">
          <xsd:sequence>
               <xsd:element name="passagers" type="passagersType"/>
          </xsd:sequence>
          <xsd:attribute name="nvol" xdb:SQLType="VARCHAR2">
               <xsd:simpleType>
                    <xsd:restriction base="xsd:string">
                         <xsd:minLength value="4"/>
                         <xsd:maxLength value="7"/>
                    </xsd:restriction>
               </xsd:simpleType>
          </xsd:attribute>
          <xsd:attribute name="datev" type="xsd:date"/>
     </xsd:complexType>
     <xsd:complexType name="passagersType" xdb:SQLType="PASSAGERS_T">
          <xsd:sequence>
               <xsd:element minOccurs="2" maxOccurs="180" name="pax" type="paxType" xdb:SQLCollType="PASSAGERS_VRY_T"/>
          </xsd:sequence>
     </xsd:complexType>
     <xsd:complexType name="paxType" xdb:SQLType="PASSAGERS_ELT_VRY_T">
          <xsd:sequence>
               <xsd:element name="nom" minOccurs="1" xdb:SQLType="VARCHAR2">
                    <xsd:simpleType>
                         <xsd:restriction base="xsd:string">
                              <xsd:minLength value="1"/>
                              <xsd:maxLength value="30"/>
                         </xsd:restriction>
                    </xsd:simpleType>
               </xsd:element>
               <xsd:element name="prenom" minOccurs="1" xdb:SQLType="VARCHAR2">
                    <xsd:simpleType>
                         <xsd:restriction base="xsd:string">
                              <xsd:minLength value="1"/>
                              <xsd:maxLength value="30"/>
                         </xsd:restriction>
                    </xsd:simpleType>
               </xsd:element>
               <xsd:element name="siege" minOccurs="1" xdb:SQLType="CHAR">
                    <xsd:simpleType>
                         <xsd:restriction base="xsd:string">
                              <xsd:minLength value="1"/>
                              <xsd:maxLength value="3"/>
                         </xsd:restriction>
                    </xsd:simpleType>
               </xsd:element>
               <xsd:element name="prix" minOccurs="1" xdb:SQLType="NUMBER">
                    <xsd:simpleType>
                         <xsd:restriction base="xsd:decimal">
                              <xsd:fractionDigits value="2"/>
                              <xsd:totalDigits value="4"/>
                         </xsd:restriction>
                    </xsd:simpleType>
               </xsd:element>
          </xsd:sequence>
          <xsd:attribute name="num_carte" type="xsd:int"/>
     </xsd:complexType>
</xsd:schema>
----- xml schema registration
BEGIN
--DBMS_XMLSCHEMA.DELETESCHEMA
-- ('http://www.iut-blagnac.fr/vols.xsd',DBMS_XMLSCHEMA.DELETE_CASCADE_FORCE);
DBMS_XMLSCHEMA.REGISTERSCHEMA(
SCHEMAURL => 'http://www.iut-blagnac.fr/vols.xsd',
SCHEMADOC => BFILENAME('REPXML','vol_reel_annote.xsd'),
LOCAL => TRUE, GENTYPES => TRUE, GENTABLES => FALSE,
CSID => NLS_CHARSET_ID('AL32UTF8'));
END;
Your succesful update becomes with my configuration :
SQL> UPDATE vol_reel_xml_2 v
2 SET v.object_value =
3 updateXML( v.object_value,
4 '/vol_reel/passagers/pax[@num_carte=13457934]/prix/text()'
5 , 198 )
6 WHERE XMLExists('/vol_reel[@nvol="AF6154" and @datev="2012-08-31"]'
7 passing v.object_value);
SET v.object_value =
ERROR at line 2:
ORA-19162: XPTY0004 - XQuery type mismatch: invalid argument types 'xs:date',
'xs:string' for function '='
By translating the xsd:datetime / Oracle date :
SQL> UPDATE vol_reel_xml_2 v
2 SET v.object_value =
3 updateXML( v.object_value,
4 '/vol_reel/passagers/pax[@num_carte=13457934]/prix/text()',198)
5 WHERE XMLExists('/vol_reel[@nvol="AF6154"]'passing v.object_value)
6 AND TO_DATE(XMLCAST(
7 XMLQUERY('$obj/vol_reel/@datev'
8 PASSING BY VALUE OBJECT_VALUE AS "obj"
9 RETURNING CONTENT)
10 AS VARCHAR2(12)),'YYYY-MM-DD')
11 = TO_DATE('2012-08-31','YYYY-MM-DD');
1 row updated.
I think my fault came from the fact I performed the test num_carte=13457934 in the UPDATE WHERE clause instead of the XPath predicate as previously.
Thanks again

Similar Messages

  • ORA-00600: internal error code while using UpdateXML to update xml content

    Hi,
    I have been using the UpdateXML command to replace content of xml stored in XMLType. It was working absolutely fine.
    Below is the query:
    UPDATE temp d SET d.message_content = updateXML(d.message_content,'//*[.="Test" ]/text()','"Test123"') WHERE                          existsNode(d.message_content,'//*[.="Test"]')=1";
    But now i'm getting an exception as follows:
    ORA-00600: internal error code, arguments: [qmcxeUpdateXml:2.1], [], [], [], [], [], [], []
    The table uses a Free Test Index.
    I searched the forum and found from the given link https://forums.oracle.com/forums/thread.jspa?threadID=2352772 that corrupted Index may be the cause of this problem. I'm still clueless :(
    Can someone help me?

    Hi sprightee,
    That thread you found seems to be a different problem (Ora-600 argument is different)
    I think you have hit bug 6811908, at least if Odie is correct about your version.
    Bug says No workaround - Fixed in 11.1.0.8
    Regards
    Peter

  • Issue in updating the Huge XML by using updatexml function

    Hi All,
    Database Credentails:
    Oracle 9i R2.
    I have a huge xml like this,
    <Root>
    <abc></abc>
    <abc></abc>
    <abc></abc>
    </Root>
    The <abc></abc> will be more than 10000 under the <Root> tag.
    I have tried to update this xml by using the following script,
    for i in 1 .. 10000
    loop
    SELECT UPDATEXML(v_xml,'/Root/abc['|| i ||']','<abc>'|| i || '<abc>')
    INTO v_xml;
    dbms_output.put_line(i); -- Just to check how many values were updated
    end loop;
    While executing the above sample code, i am getting the error called
    INVALID XPATH EXPRESSION,
    some times it is executing to some number after that i am getting the above error. when i try execute the same code again i will get error for different i value.
    Could you please help me out to fix this bug/mistake for me. Please provide me some sample code for this.
    Thanks in Advance,
    Vinoth Kumar S.

    You don't need any loop for this. simple UPDATEXML statement should do.
    sql> WITH myxmltab AS
      2  (SELECT XMLTYPE('<Root>
      3  <abc>4</abc>
      4  <abc>5</abc>
      5  <abc> </abc>
      6  <abc> </abc>
      7  <abc> </abc>
      8  <abc></abc>
      9  <abc></abc>
    10  <abc></abc>
    11  <abc></abc>
    12  <abc></abc>
    13  </Root>') xmlcol FROM dual)
    14  select UPDATEXML(t.column_value,'/abc',xmltype('<abc>' || rownum || '</abc>')) from myxmltab,
    15  table(xmlsequence(extract(xmlcol,'/Root/abc'))) t;
    UPDATEXML(T.COLUMN_VALUE,'/ABC',XMLTYPE('<ABC>'||ROWNUM||'</ABC>'))
    <abc>1</abc>
    <abc>2</abc>
    <abc>3</abc>
    <abc>4</abc>
    <abc>5</abc>
    <abc>6</abc>
    <abc>7</abc>
    <abc>8</abc>
    <abc>9</abc>
    <abc>10</abc>
    10 rows selected.
    Elapsed: 00:00:00.04

  • Error while using dbms_xmlsave.UpdateXML and dbms_xmlsave.insertXML

    The Record I am trying to insert/update has the following structure
    <ROWSET>
    <ROW>
    <COL1>123</COL1>
    </ROW>
    </ROWSET>
    Table structure is as below
    COL1 INT [Primary constraint]
    COL2 VARCHAR2(100) NOT NULL [but has default value of 'COL2_Default']
    Now since the XML doesn't have the entry for COL2, I am explicitly setting the columns to be updated/inserted using dbms_xmlsave.setUpdateColumn.
    I use the logic the following logic to insert/update the table
    -- set the primary key column name. This forms the where clause for update statement
    dbms_xmlsave.setkeycolumn(l_Context , 'COL1');
    -- cXML have the XML structure mentioned above
    l_rows := dbms_xmlsave.updateXML(l_Context, cXML);
    IF l_rows <= 0 THEN -- which means no rows found for update
    l_rows := dbms_xmlsave.insertXML(l_Context, cXML);
    END IF;
    Now when the excution of dbms_xmlsave.updateXML happens Java Runtime Error is thrown.
    ORA-29532: Java call terminated by uncaught Java exception: oracle.xml.sql.OracleXMLSQLException: 'java.sql.SQLException: Missing IN or OUT parameter at index:: 5' encountered during processing ROW element 0. All prior XML row changes were rolled back. in the XML document.
    The version of oracle I am using is 9.2.0.6.0.
    Please let me know if anyone has any idea on this error.

    Found maybe an applicable reference...
    On http://publib.boulder.ibm.com/infocenter/wasinfo/v4r0/index.jsp?topic=/com.ibm.support.was.doc/html/Java_2_Connectivity_(J2C)/1163246.html
    it says:
    * Application code is missing a setXXX method call somewhere.
    * There might be a problem in the Oracle JDBC driver code.
    If the latter is the problem than you should or try a different JDBC driver or (which is probably the best solution anyway) create an iTar with Oracle support via metalink.oracle.com
    Other references can also be found on the internet when using google which could be applicable. Search on keywords: "Missing IN or OUT parameter at index"
    Message was edited by:
    mgralike

  • DBMS_XMLSAVE.updatexml basic problem - bug?

    I want to update a column that is also the key. i.e. \
    update salary_tab set salary=15000 where salary=10000
    how can I accomplish this using DBMS_XMLSAVE.UPDATEXML?
    Trying to figure out for 6 hours no solution :( help!
    Thanks in advance!

    Hi Pavan,
    Thanks for looking into it. However, this does not work - all the examples I found on the net dealt with different key and update columns. My case is when the key and update columns lists are overlapping.
    Thus,
    Key Column List = SALARY
    Update Column List = SALARY
    the problem is that I dont know how to specify the rowset xml now.
    <ROWSET>
    <ROW>
    <SALARY>10000</SALARY>
    <ROW>
    </ROWSET>
    how can I specify 2 nodes for salary - one to find which row to update and one to specify the new upated value.
    Is this a missing functionality in DBMS_XMLSAVE??

  • DBMS_XMLSTORE.UpdateXML error when node is empty

    We are using Oracle version 11.2.0.1.0.
    We are using DBMS_XMLStore.UpdateXML to directly update from XML and are having an issue when an empty node is passed within the XML.
    If I pass this xml to updateXML to clear out field C1 I get an error.
    <ROWSET table="My_Table">
    <record>
    <M_ID>47</M_ID>
    <C1></C1>
    <C2>999998</C2>
    <C3>2010-07-12T10:00:00</C3>
    <C4>Reason1</C4>
    </record>
    </ROWSET>
    ORA-31011: XML parsing failed
    ORA-19202: Error occurred in XML processing
    LPX-00222: error received from SAX callback function
    ORA-00927: missing equal sign
    I've seen this issue listed back in 2007 and there claims to have been a fix for version 10.2.0.1.
    Is there a fix or a workaround for this?

    Hi,
    This works for me on 11.2.0.2 :
    SQL> create table my_table (
      2   m_id number,
      3   c1 varchar2(30),
      4   c2 number,
      5   c3 date,
      6   c4 varchar2(30)
      7  );
    Table created
    SQL>
    SQL> insert into my_table
      2  values(47, 'TEST', 999999, null, null);
    1 row inserted
    SQL>
    SQL> DECLARE
      2 
      3   ctx dbms_xmlstore.ctxHandle;
      4   doc xmltype := xmltype('<ROWSET table="My_Table">
      5  <record>
      6  <M_ID>47</M_ID>
      7  <C1></C1>
      8  <C2>999998</C2>
      9  <C3>2010-07-12T10:00:00</C3>
    10  <C4>Reason1</C4>
    11  </record>
    12  </ROWSET>');
    13 
    14   res number;
    15 
    16  BEGIN
    17 
    18   ctx := dbms_xmlstore.newContext('MY_TABLE');
    19   dbms_xmlstore.setRowTag(ctx, 'record');
    20   dbms_xmlstore.setKeyColumn(ctx, 'M_ID');
    21   dbms_xmlstore.setUpdateColumn(ctx, 'C1');
    22   dbms_xmlstore.setUpdateColumn(ctx, 'C2');
    23   res := dbms_xmlstore.updateXML(ctx, doc);
    24 
    25  END;
    26  /
    PL/SQL procedure successfully completed
    SQL> select * from my_table;
          M_ID C1                 C2 C3          C4
            47                999998

  • How can i append new xml node to xmltype doc with updatexml and xpath?

    ex. content of column:
    <xmldoc>
    <xmlnode attr="x" value="x1"/>
    <xmlnode attr="y" value="y1"/>
    </xmldoc>
    needed to be:
    <xmldoc>
    <xmlnode attr="x" value="x1"/>
    <xmlnode attr="y" value="y1"/>
    <xmlnode attr="z" value="z1"/>
    <xmldoc/>
    how can i do this with updatexml without rewriting all xmlnode-elements?

    You have to specify the DTD in the transformation. If you are using XSLT then you do that on your <xsl:output>. Otherwise you need to give more details.

  • UpdateXML feature or bug?

    Stupid server error again duplicating my threads... Grrrr!
    Message was edited by:
    blushadow

    Not a bug
    Your xpath identifies the node value3. You are replacing that node with a scalar value (eg a text() node). So you are ineffect generating mixed text. for element1, eg it has both text() and element nodes as children. I'm a little suprised at the fact that the text() node appears before value1 in this case. I think what you are trying to do is replace the text() node child of value3 with a new text() node. In which case the updateXML() should be
    update txml
      set x = updateXML(x,'/root/element1/value3/text()','3')
      where id = 1;Note that the xpath now references the text() node child of value3, not the node value3. ExtractValue() is a little deviant from the Xpath spec, in that it is the only case where we will assume that if you reference as a simpleType element you are actually referencing the text() node child of the specified element. We cannot do this in other cases as it is legal, although somwhat unusal, to replace an element with a text() node.

  • UpdateXML for non-existing attribute

    Hello
    bellow are data for a sreange looking (for me) behaviour of updateXML.
    Usually (i mean other languages) setting an xml node attribute causes attribute creation if it does not exist.
    Here obviously that is not the case.
    Q: Why and is it possible to create attribute during node update?
    thank you
    i
    h3. general info
    SQL&gt; select * from v$version;
    BANNER
    Oracle9i Enterprise Edition Release 9.2.0.7.0 - Production
    PL/SQL Release 9.2.0.7.0 - Production
    CORE 9.2.0.7.0 Production
    TNS for 32-bit Windows: Version 9.2.0.7.0 - Production
    NLSRTL Version 9.2.0.7.0 - Production
    SQL&gt; select dbms_metadata.get_DDL('TABLE', 'X') FROM dual;
    DBMS_METADATA.GET_DDL('TABLE',
    CREATE TABLE "PCB_1209"."X"
    ( "NODE" "SYS"."XMLTYPE"
    ) PCTFREE 10
    SQL&gt;
    SQL&gt; insert into x values(Xmltype('&lt;TOP&gt;&lt;DATAID&gt;111080&lt;/DATAID&gt;&lt;/TOP&gt;'));
    SQL&gt; insert into x values(Xmltype('&lt;TOP&gt;&lt;DATAID lbl="test"&gt;111000&lt;/DATAID&gt;&lt;/TOP&gt;'));
    SQL&gt; commit;
    Commit complete
    h3. correct part
    SQL&gt;
    SQL&gt; select extract(node, '/').getStringVal() as node
    2 from x where extract(node, '//DATAID/text()').getNumberVal() = 111000;
    NODE
    &lt;TOP&gt;
    &lt;DATAID lbl="test"&gt;111000&lt;/DATAID&gt;
    &lt;/TOP&gt;
    SQL&gt;
    SQL&gt; update x set node = updateXML(node,'//DATAID/@lbl','test_new')
    2 where extract(node, '//DATAID/text()').getNumberVal() = 111000;
    1 row updated
    SQL&gt; commit;
    Commit complete
    SQL&gt;
    SQL&gt; select extract(node, '/').getStringVal() as node
    2 from x where extract(node, '//DATAID/text()').getNumberVal() = 111000;
    NODE
    &lt;TOP&gt;
    &lt;DATAID lbl="test_new"&gt;111000&lt;/DATAID&gt;
    &lt;/TOP&gt;
    h3. wrong part
    SQL&gt;
    SQL&gt; select extract(node, '/').getStringVal() as node
    2 from x where extract(node, '//DATAID/text()').getNumberVal() = 111080;
    NODE
    &lt;TOP&gt;
    &lt;DATAID&gt;111080&lt;/DATAID&gt;
    &lt;/TOP&gt;
    SQL&gt;
    SQL&gt; update x set node = updateXML(node,'//DATAID/@lbl','test_new')
    2 where extract(node, '//DATAID/text()').getNumberVal() = 111080;
    1 row updated
    SQL&gt; commit;
    Commit complete
    SQL&gt;
    SQL&gt; select extract(node, '/').getStringVal() as node
    2 from x where extract(node, '//DATAID/text()').getNumberVal() = 111080;
    NODE
    &lt;TOP&gt;
    &lt;DATAID&gt;111080&lt;/DATAID&gt;
    &lt;/TOP&gt;

    Unusual, probably. Documented, yes. This is from 10.2 but would still be applicable to you and your situation.
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14214/chapter1.htm#FEATURENO05479
    The current UpdateXML() function can only manipulate the content of existing nodes within an XML document. It cannot be used to add or remove nodes from a document. The only way to add or remove nodes from a document is to use the methods provided by the DOM API.So you are going to have to insert/create that attribute in the XML before you can update it. I was going to provide a link to some examples but I can't seem to recall where I saw them in the forums. I thought it was on {forum:id=75} but I can't find it now.

  • Use UpdateXml

    Hi,
    I have a table which contains XML in a clob.
    The xml looks something like this:
    <form>
         <formfield>
              <fieldname>FieldA</fieldname>
              <fieldvalue>aaaaa</fieldvalue>
         </formfield>
         <formfield>
              <fieldname>FieldB</fieldname>
              <fieldvalue>bbbb</fieldvalue>
         </formfield>
         <formfield>
              <fieldname>FieldC</fieldname>
              <fieldvalue>cccc</fieldvalue>
         </formfield>
         <formfield>
              <fieldname>FieldD</fieldname>
              <fieldvalue>dddd</fieldvalue>
         </formfield>
    </form>
    I want to update the fieldvalue, if the fieldname is for instance 'FieldC' with PL/SQL. Not all records have a 'FieldC'.
    I thought of using xPath for this, so I first check whether 'FieldC' does exists (I've put the xml in variable y):
    if y.existsNode('/form/formfield[fieldname = "FieldC"]') = 1 then
    end if
    But now I'm strucling with how to replace the fieldvalue 'cccc' with the new value.
    I was thinking of using updateXML for this, but I don't know how to find the right fieldvalue (so only the fieldvalue of the parent of 'FieldC').
    Thanks.
    Bibi
    Any other solutions, without using updateXML are also welcome.

    Well this can be done with a simple UpdateXML, using an appropriate XPath expression...
    SQL> ed
    Wrote file afiedt.buf
      1  with t as (select xmltype('<form>
      2  <formfield>
      3  <fieldname>FieldA</fieldname>
      4  <fieldvalue>aaaaa</fieldvalue>
      5  </formfield>
      6  <formfield>
      7  <fieldname>FieldB</fieldname>
      8  <fieldvalue>bbbb</fieldvalue>
      9  </formfield>
    10  <formfield>
    11  <fieldname>FieldC</fieldname>
    12  <fieldvalue>cccc</fieldvalue>
    13  </formfield>
    14  <formfield>
    15  <fieldname>FieldD</fieldname>
    16  <fieldvalue>dddd</fieldvalue>
    17  </formfield>
    18  </form>') as xml from dual)
    19  --
    20  select updateXML(xml, '/form/formfield[fieldname="FieldC"]/fieldvalue/text()', 'xxxx') as xml
    21* from t
    SQL> /
    XML
    <form><formfield><fieldname>FieldA</fieldname><fieldvalue>aaaaa</fieldvalue></formfield><formfield><
    fieldname>FieldB</fieldname><fieldvalue>bbbb</fieldvalue></formfield><formfield><fieldname>FieldC</f
    ieldname><fieldvalue>xxxx</fieldvalue></formfield><formfield><fieldname>FieldD</fieldname><fieldvalu
    e>dddd</fieldvalue></formfield></form>
    SQL>Edited by: BluShadow on Dec 1, 2009 3:01 PM
    slight correction

  • UpdateXML : How to update EmployeeName tag based on EmployeeID value

    Hi All,
    My XMLType (EMP_DOCUMENT) field in a table stores the following simple XML structure:
    <DEPARTMENT>
         <DEPARTMENT_ID>1</DEPARTMENT_ID>
         <DEPARTMENT_NAME>Finance</DEPARTMENT_NAME>
         <EMPLOYEE>
              <EMPLOYEE_ID>1</EMPLOYEE_ID>
              <FIRST_NAME>ABC</FIRST_NAME>
              <EMAIL>ABC</EMAIL>
    </EMPLOYEE>
         <EMPLOYEE>
              <EMPLOYEE_ID>2</EMPLOYEE_ID>
              <FIRST_NAME>xyz</FIRST_NAME>
              <EMAIL>xyz</EMAIL>
    </EMPLOYEE>
         <EMPLOYEE>
              <EMPLOYEE_ID>3</EMPLOYEE_ID>
              <FIRST_NAME>zzzz</FIRST_NAME>
              <EMAIL>zzz</EMAIL>
    </EMPLOYEE>
         <EMPLOYEE>
              <EMPLOYEE_ID>4</EMPLOYEE_ID>
              <FIRST_NAME>yyyy</FIRST_NAME>
              <EMAIL>yyyy</EMAIL>
    </EMPLOYEE>
    </DEPARTMENT>
    Employee_ID is unique and Employee_Name is not unique.
    I have a requirement to update the Employee_Name tag where i have the Employee_ID and the value to be updated.I tried the following but it updates all Employee_Names instead of updating the record i want:
    UPDATE EMPLOYEE_DOCUMENTS p
    SET p.EMP_DOCUMENT = updateXML(p.EMP_DOCUMENT,
                   '/DEPARTMENT/EMPLOYEE/FIRST_NAME/text()',
              'Scott')
    WHERE DOCUMENT_ID = 1
    AND existsNode(p.EMP_DOCUMENT,'/DEPARTMENT/EMPLOYEE[EMPLOYEE_ID = 2')=1
    I can see that updateXML essentially acts as 'ReplaceXML' where one tag can be searched and replaced with the new value.But is it possible to UPDATE a tag based on other tag at the same level (like update the employee_name based on employee_id)
    Thanks,
    Srihari
    Edited by: srihari manian on Jul 15, 2009 7:19 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    I believe this is what you are looking for
    WITH employee_documents AS
    (SELECT XMLTYPE('<DEPARTMENT>
    <DEPARTMENT_ID>1</DEPARTMENT_ID>
    <DEPARTMENT_NAME>Finance</DEPARTMENT_NAME>
    <EMPLOYEE>
    <EMPLOYEE_ID>1</EMPLOYEE_ID>
    <FIRST_NAME>ABC</FIRST_NAME>
    <EMAIL>ABC</EMAIL>
    </EMPLOYEE>
    <EMPLOYEE>
    <EMPLOYEE_ID>2</EMPLOYEE_ID>
    <FIRST_NAME>xyz</FIRST_NAME>
    <EMAIL>xyz</EMAIL>
    </EMPLOYEE>
    <EMPLOYEE>
    <EMPLOYEE_ID>3</EMPLOYEE_ID>
    <FIRST_NAME>zzzz</FIRST_NAME>
    <EMAIL>zzz</EMAIL>
    </EMPLOYEE>
    <EMPLOYEE>
    <EMPLOYEE_ID>4</EMPLOYEE_ID>
    <FIRST_NAME>yyyy</FIRST_NAME>
    <EMAIL>yyyy</EMAIL>
    </EMPLOYEE>
    </DEPARTMENT>') emp_document
      FROM DUAL
    SELECT updateXML(p.EMP_DOCUMENT,
    '/DEPARTMENT/EMPLOYEE[EMPLOYEE_ID = 2]/FIRST_NAME/text()',
    'Scott')
      FROM employee_documents pwhich just updates the name for employee id 2.

  • UpdateXML on a xmlType table

    I am getting "end of file on communication channel" when I try to update an element using updateXML. This heppens when I set both genTables and storeVarrayAsTable to true.
    If I set storeVarrayAsTable to false, the same updateXML works fine.
    Has anyone encountered the same problem? Is updateXML supposed work with nested tables?

    Here is the TAR number 3897519.994
    VARRAY gives me reasonable performance overall, but I haven't seem the same level of stabitily and performance from nested tables. I realized that one of complexElement is recurrsive so that I added xdb:SQLType="CLOB" to it, but it didn't help.
    I don't know if the performance which I got so far is as fast as it can go.
    Thanks

  • Updatexml on xmltype variable

    Is there a way to update the XML in an xmltype variable?
    I don't want to have to use the sql commands update ... set that constrain me to changing XML already stored in a table.
    For example this is what I would like to do. If I have the following XML in clob vXmlClob
    <Action>
    <User>SVOLLMAN</User>
    </Action>
    I want to change the user to Dave...
    declare
    vXmlType xmltype;
    vXmlClob clob;
    begin
    vXmlType := xmltype(vXmlClob);
    vXmlType := xmlType.updatexml('Action/User','Dave');
    end;
    Of course this does not work but is there another way of updating the XML in my variable. Or maybe I am looking at this the wrong way - is there any way of using the update ... set sql commands without having the XML already in a table.

    You mean this?:
    michaels>  select xml, updatexml (d.xml, 'Action/User/text()', 'Dave') updated_xml
      from (select xmltype ('<Action><User>SVOLLMAN</User></Action>') xml from dual) d
    XML                                        UPDATED_XML                          
    <Action><User>SVOLLMAN</User></Action>     <Action><User>Dave</User></Action>                                                                                        

  • Updatexml function is returning error. Syntax problem....

    I have a xmlfile which is shown below...
    cat MYTEMP.xml
    <?xml version="1.0" encoding = "AL32UTF8"?>
    <ROWSET>
    <ROW>
    <EDETAIL>test</EDETAIL>
    <T1>3</T1>
    </ROW>
    <ROW>
    <EDETAIL> test1</EDETAIL>
    <T1>4</T1>
    </ROW>
    <ROW>
    <EDETAIL>test2 </EDETAIL>
    <T1>2</T1>
    </ROW>
    <ROW>
    <EDETAIL> </EDETAIL>
    <T1>1</T1>
    </ROW>
    <ROW>
    <EDETAIL> </EDETAIL>
    <T1>5</T1>
    </ROW>
    </ROWSET>
    I load this xmlfile into a xmltype column in a global temporary table.
    I have to update edetail tag to '~:' if it contains only whitespace(s) in it.
    I am trying the following command and its giving me error....
    insert into gt_xmltype_tab(xmlfile1)
    values(XMLType(bfilename('RESTOREDIR','MYTEMP.xml'),nls_charset_id('AL32UTF8')));
    update gt_xmltype_tab set xmlfile1 = updatexml(xmlfile1, '/ROWSET/ROW/EDETAIL/text()','~:')
    where extractvalue(xmlfile1, '/ROWSET/ROW/EDETAIL') IS NULL
    I get the following error for the updatexml...
    update gt_xmltype_tab set XMLFILE1 = updatexml(XMLFILE1 , '/ROWSET/ROW/EDETAIL/text()','~:')
    ERROR at line 1:
    ORA-19025: EXTRACTVALUE returns value of only one node
    What is the correct way of doing it? What am I doing wrong?

    What is the correct way of doing it? What am I doing wrong?The WHERE clause filters records from the table, not repeating elements from the XML document.
    Actually, I'm not sure if you want one or the other...
    If you've got multiple XML files in the table, and want to update (the table) only where there's something to update, then use existsNode in the WHERE clause to check if the XML possesses at least an "empty" element.
    If there's only one XML in the table, no WHERE clause necessary.
    As for the update (of the XML document), that's a little tricky.
    Once into the table, whitespaces are not preserved, so there's actually no text() node to update.
    A solution is to update the element as a whole :
    UPDATE gt_xmltype_tab
    SET xmlfile1 = updateXML( xmlfile1
                            , '/ROWSET/ROW/EDETAIL[not(text())]'
                            , XMLElement("EDETAIL", '~:') )
    ;

  • Serious updatexml bug

    Consider this query:
    select updatexml(xmltype('<r>a<z/>b</r>'),'//z','x').getstringval() from dual;I expect the following result:
    <r>axb</r>Instead, I get this:
    <r>abx</r>Now with multiple z elements:
    select updatexml(xmltype('<r>a<z/>b<z/>c</r>'),'//z','x').getstringval() from dual;I expect the following result:
    <r>axbxc</r>Instead, I get this:
    <r>abcxx</r>It seems to me that updatexml concatenates all text nodes first before applying replacements when the replacement is a text.
    How do I log a bug for this?

    Ben
    Let me check with development whether they agree with your conclusion that this is incorrect behavoir. My initial reaction is that I agree with you that this is a bug, and it would not suprise me. To date we've seen very little use of mixed text with XML DB, yet alone someone attempting to replace an element node with a text node in a mixed text parent...
    In terms of how do you file a bug. If you have a valid oracle support contract you can open a tar via Oracle Metalink. The support analysts will then verify that this is a bug and open one on your behalf.
    However since the testcase for this is so simple I'll file it on your behalf, once I get confirmation from development that the behavoir is indeed incorrect. At that point I'll post the bug number here.
    If this is a serious problem that you need a fix for you'll need to open a tar at that point ( assuming you have a valid support contract) and request that a patch for this bug be provided. You'll need to provide a strong business justiificaiton explaining the impact of this on the your project and organization and why you need a fix for this issue.
    I'm guessing you could work around this using DBMS_XMLDOM package if it's absolutely criitical.

  • XSU updateXML problems

    Hi,
    I've a table, tab sequence, with the following structures:
    Name Null? Type
    TABLENAME NOT NULL VARCHAR2(50)
    SEQUENCE_NO NUMBER(10)
    I've generated an XML document, abc.xml, using the following code segments:
    import oracle.jdbc.driver.*;
    import oracle.xml.sql.query.OracleXMLQuery;
    import java.lang.*;
    import java.sql.*;
    import java.io.*;
    // class to test the String generation!
    class testXMLSQL {
    public static void main(String[] argv)
    try{
    // create the connection
    Connection conn = getConnection("john","ajohn");
    // Create the query class.
    OracleXMLQuery qry = new OracleXMLQuery(conn, "select * from tabsequence");
    // Get the XML string
    String str = qry.getXMLString();
    // Print the XML output to screen
    // System.out.println(" The XML output is:\n"+str);
    writeToFile("abc.xml",str);
    // Always close the query to get rid of any resources..
    qry.close();
    }catch(SQLException e){
    System.out.println(e.toString());
    // Get the connection given the user name and password..!
    private static Connection getConnection(String username, String password)
    throws SQLException
    // register the JDBC driver..
    DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
    // Create the connection using the OCI8 driver
    Connection conn =
    DriverManager.getConnection("jdbc:oracle:thin:@10.37.108.122:1220:lslva",username,password);
    return conn;
    private static void writeToFile(String fileName,String fileContent) {
    try {
         FileOutputStream fo=new FileOutputStream(fileName);
         PrintStream ps=new PrintStream(fo);
         ps.println(fileContent);
         ps.close();
         fo.close();
    catch(Exception ex){
         System.out.println(ex);
    After I've made some modifications to the 'sequence_no' of the abc.xml,
    I've attempted to execute the following code segment to update the
    tabsequence table:
    import java.sql.*;
    import oracle.xml.sql.dml.OracleXMLSave;
    import java.net.*;
    public class testUpdate
    public static void main(String argv[])
    throws SQLException
    String tabName = "tabsequence";
    String fileName = "abc.xml";
    Connection conn = getConnection("john","ajohn");
    OracleXMLSave sav = new OracleXMLSave(conn, tabName);
    String [] keyColNames = new String[1];
    keyColNames[0] = "TABLENAME";
    sav.setKeyColumnList(keyColNames);
    String[] updateColNames = new String[2];
    updateColNames[0] = "SEQUENCE_NO";
    sav.setUpdateColumnList(updateColNames);
    URL url = sav.getURL(fileName);
    int rowCount = sav.updateXML(url);
    sav.close();
    System.out.println(" Successfully updated "+rowCount+ " rows into "+ tabName);
    conn.close();
    // Get the connection given the user name and password..!
    private static Connection getConnection(String user, String passwd)
    throws SQLException
    DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
    Connection conn =
    DriverManager.getConnection("jdbc:oracle:thin:@10.37.108.122:1220:lslva",user,passwd);
    return conn;
    It always gives me the following error message:
    Exception in thread "main" oracle.xml.sql.OracleXMLSQLException: NULL NOT A VALID COLUMN NAME.
    at oracle.xml.sql.dml.OracleXMLSave.saveXML(OracleXMLSave.java:2361)
    at oracle.xml.sql.dml.OracleXMLSave.saveXML(OracleXMLSave.java:2233)
    at oracle.xml.sql.dml.OracleXMLSave.updateXML(OracleXMLSave.java:1595)
    at testUpdate.main(testUpdate.java:26)
    PLEASE HELP! THANKS

    Hi,
    I think there is a problem with the definition of the columns to be updated :
    String[] updateColNames = new String[2];
    updateColNames[0] = "SEQUENCE_NO";
    sav.setUpdateColumnList(updateColNames);
    You fill only the first element of the array, the second one is null!
    Try
    String[] updateColNames = new String[1];
    instead...
    However, I haven't tried it out!
    HTH,
    Bernhard

Maybe you are looking for

  • Parent / Child forms or sharing a parent region across child tabs

    I want to find a way to have the same region appear on multiple pages. ApEx has a good master / detail form wizard. And I have used other constructs (master view, report, "add a detail record button", etc) to make the screens more user friendly, less

  • How to send file to FTP on conditional basis.

    Hi SAP Guru's, Can somebody please tell me how to create a file on conditional basis in FTP. My requirement is that I have to create a file in different directory according to the sender port field. Interface IDOC - > XI - > File SNDPRN(DGE008,DGE006

  • Problem with a small code

    Hello , Can anyone plz tell me how do i get this output from this sample code ? im new to java... public class Fact2 int factorial (int n) { int res; System.out.println(n); if (n == 1) return 1; res = factorial (n - 1) * n ; System.out.println("res "

  • Unable to call a Packaged function in SQL statement??

    I have written a package & overloaded a function 3 times. I am using different parameter name for overloading & call as follows: my_pkg.ovrld_func(p_1 => v_val) my_pkg.ovrld_func(p_2 => v_val) my_pkg.ovrld_func(p_3 => v_val) When i use this statement

  • LOV refresh issue

    Hi , I have a LOV switcher attribute in my VO. After saving my page, I need the getter of the switcher to be executed so that the page shows the correct LOV returned by the switcher. How do I go abt it? Appreciate your help on this.