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>                                                                                        

Similar Messages

  • XQUERY against an XMLTYPE variable

    I have a procedure which gets xmltype instance and i have to use xquery upon that variable.
    declare
    myxml xmltype;
    s varchar2(20);
    begin
    myxml:=xmltype('<person><name id="1" age="23"/><name id="2" age="25"/></person>');
    SELECT
    XMLQuery(
    'for $i in /person
    where $i/age > 24
    return $i/id'
    PASSING myxml RETURNING CONTENT) into s
    FROM DUAL;
    end;
    BUT i get this error
    ORA-06550: line 6, column 1:
    PLS-00801: internal error [*** ASSERT at file pdw4.c, line  793; Cannot coerce
    between type 43 and type 30; anon_68F441E0__AB[6, 1]]
    Please help it is urgent

    Not sure if you ever received your answer regarding how to pass an XMLType variable in PLSQL to an XQuery command.
    Here is an example of what I've been using... in Oracle 10.2.0.1
    SET SERVEROUTPUT ON SIZE 200000
    DECLARE
    l_result XMLType;
    l_xxDoc XMLType := XMLType(
    <root>
    <things>
    <somestuff>12345</somestuff>
    <morestuff>12345</morestuff>
    </things>
    <things>
    <somestuff>dfgdfg</somestuff>
    <morestuff>werwer</morestuff>
    </things>
    </root>
    PROCEDURE printClobOut
    (p_result IN CLOB)
    IS
    v_xmlstr VARCHAR2(32767);
    v_line VARCHAR2(2000);
    BEGIN
    v_xmlstr := DBMS_LOB.SUBSTR(p_result,32767);
    LOOP
    EXIT WHEN v_xmlstr IS NULL;
    v_line := SUBSTR(v_xmlstr,1,INSTR(v_xmlstr,CHR(10))-1);
    DBMS_OUTPUT.PUT_LINE('| '||v_line);
    v_xmlstr := SUBSTR(v_xmlstr,INSTR(v_xmlstr,CHR(10))+1);
    END LOOP;
    END;
    BEGIN
    select XMLQUERY(
    'for $a in $TheDoc/root
    return <theresult>
    {$a/things}
    </theresult>
    PASSING l_xxDoc as "TheDoc"
    RETURNING CONTENT) into l_result
    from dual;
    printClobOut(l_result.extract('/').getClobVal());
    END;
    Kevin

  • Reorder an xmltype variable in plsql

    I have an xml package sitiing in an xmltype variable.
    Does anyone know a way I can reorder the nodes alphabetically?
    Many Thanks
    Paul

    I can't post the xml.
    The forum just keeps saying content is not allowed.Use &#x7B;code} tags to enclose any code snippets you want to post. It'll preserve formatting and prevent content to be interpreted on the page.
    It's explained here : http://forums.oracle.com/forums/help.jspa
    Does this work for you :
    SQL> set serveroutput on
    SQL>
    SQL> DECLARE
      2 
      3   doc xmltype := xmltype(
      4   '<root>
      5  <things>bbb
      6  <somestuff>1234</somestuff>
      7  <morestuff>5678</morestuff>
      8  </things>
      9  <things>aaa
    10  <somestuff>dog</somestuff>
    11  <morestuff>cat</morestuff>
    12  </things>
    13  </root>'
    14   );
    15 
    16   ordered_doc xmltype;
    17 
    18  BEGIN
    19 
    20   select xmlquery(
    21   'for $i in $d/*
    22    return element {name($i)}
    23    {
    24     for $j in $i/things
    25     order by $j/text()
    26     return $j
    27    }'
    28    passing doc as "d"
    29    returning content
    30   )
    31   into ordered_doc
    32   from dual;
    33 
    34   dbms_output.put_line(ordered_doc.getclobval());
    35 
    36  END;
    37  /
    <root><things>aaa
    <somestuff>dog</somestuff>
      <morestuff>cat</morestuff>
    </things>
    <things>bbb
    <somestuff>1234</somestuff>
      <morestuff>5678</morestuff>
    </things>
    </root>
    PL/SQL procedure successfully completed
    The first "for" in the XQuery is there in case you don't want to hardcode the root element.

  • Is it possible to concatenate XMLType variable

    I'm using XQuery to query relational table and store the result into an xmltype variable as shown below:
    SELECT XMLQuery('<Data>
    {for $c in ora:view("TABLEA")
           let $id := $c/ROW/ID/text(), $code := $c/ROW/CODE/text(),
               return
           <result>
             <type>I</type>
             <id>{$id}</id>
    <code>{$code}</code>
    </result> </Data>' RETURNING CONTENT)
    INTO V_Delete FROM dual;
    Similarly, I query other tables and store the result in xmltype variable. My requirement is to generate one xml file out of it. This would mean that I would need to consolidate the values stored in different xmltype variables. Is it possible to concatenate the xmltype varialbe? If so, how? If not, what is the alternative? I tried converting it to string, but then the 4000 limit caused an error.

    Hi, as I said I have not done that myself. But you can read chapter 4 of the XDB Developer's Guide of the Oraclce docs and I think it may help. The examples there show that those functions are used to update a table. It has this example,
    UPDATE purchaseorder
    SET OBJECT_VALUE =
    appendChildXML(OBJECT_VALUE,
    '/PurchaseOrder/Actions/Action[1]',
    XMLType('<Date>2002-11-04</Date>'))
    WHERE existsNode(OBJECT_VALUE,
    '/PurchaseOrder[Reference="AMCEWEN-20021009123336171PDT"]')
    = 1;
    SELECT extract(OBJECT_VALUE, '/PurchaseOrder/Actions/Action[1]')
    FROM purchaseorder
    WHERE existsNode(OBJECT_VALUE,
    '/PurchaseOrder[Reference="AMCEWEN-20021009123336171PDT"]')
    = 1;
    That was why I thought using a global temp table would help in this kind of operation. What I did was using select xmlelement(namespace declarations) from dual, then using a nested (select xmlelement() ) inside the from dual part. I have to select from many different tables to create one xml and it works for me, but I did not try the other ways. If you just need to attach the prolog and namespace stuff, you can store them in a clob or varchar2 var and convert the xml to clob and that simply concantenate them, and then convert the clob back to xml. In 10g there is also the new XMLProlog (I forgot the exact name at this moment) function. Check that out and see if it will work for you.
    ben

  • XMLTYPE variable converting to XML (Question)

    Friends,
    I am stuck on an error and cannot find a way out. Please help. I know it's a long question but a very simple answer to many smart people here. I am just lost and need your help. (I am new to SOA so bear with me)
    I have a BPEL process which invokes a PL/SQL API which returns the XMLTYPE output which has the XML data. In order to convert the XMLTYPE to normal XML I do following :-
    - I added a Java embed activity in BPEL with following code (Invoke_new_get_customer_order_info_OutputVariable','OutputParameters','/ns2:OutputParameters/ns2:X_CUSTOMER_ORDER_INFO_XML is the XMLTYPE)
    (responsePayoad is string variable)
    try{                                                           
    Node node = (Node)getVariableData("Invoke_new_get_customer_order_info_OutputVariable','OutputParameters','/ns2:OutputParameters/ns2:X_CUSTOMER_ORDER_INFO_XML");
    Node childNode = (Node) node.getFirstChild();
    StringWriter writer = new StringWriter();
    Transformer transformer = TransformerFactory.newInstance().newTransformer();
    transformer.transform(new DOMSource(childNode), new StreamResult(writer));
    String xml = writer.toString();
    String nsXML = xml.replaceFirst("<FetchCustomerInfoResponse","<FetchCustomerInfoResponse xmlns=\"http://xmlns.djoglobal.com/OrderTracking/CustomerInfo\" ");
    setVariableData("responsePayload",nsXML);
    addAuditTrailEntry("XML with Namespace: " + nsXML);
    } catch(Exception e){                            
    addAuditTrailEntry(e);
    System.out.println("Namespace injection failed due to : " + e);
    After above I have ASSIGN activity where I use parsexml function on the "responsePayload" variable to assign to a variable of type element which refers to following xsd. This is where I get an "internal xpath error" during runtime which I cannot resolve.
    XSD of the element variable refering to "FetchCustomerInfoResponse" element
    <?xml version="1.0" encoding="windows-1252" ?>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns="http://www.example.org"
    targetNamespace="http://xmlns.djoglobal.com/OrderTracking/DJOFetchCustomerOrderInfo"
    elementFormDefault="qualified">
    <xsd:element name="FetchCustomerInfoResponse">
    <xsd:complexType>
    <xsd:sequence>
    <xsd:element name="DJO_ONT_ACCOUNT_ORDERS">
    <xsd:complexType>
    <xsd:sequence>
    <xsd:element name="DJO_ONT_ACCOUNT_ORDER" maxOccurs="unbounded">
    <xsd:complexType>
    <xsd:attribute name="ordered_date" type="xsd:string"/>
    <xsd:attribute name="cust_po_number" type="xsd:string"/>
    <xsd:attribute name="order_number" type="xsd:integer"/>
    <xsd:attribute name="header_id" type="xsd:integer"/>
    </xsd:complexType>
    </xsd:element>
    </xsd:sequence>
    </xsd:complexType>
    </xsd:element>
    </xsd:sequence>
    </xsd:complexType>
    </xsd:element>
    </xsd:schema>
    XML returned in the XMLTYPE from the PL/SQL API :-
    <Invoke_new_get_customer_order_info_OutputVariable><part name="OutputParameters" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <OutputParameters xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.oracle.com/pcbpel/adapter/db/APPS/XXDJO_ONT_ORDER_TRACKING_WS/GET_CUSTOMER_ORDER_INFO_XML/"><X_CUSTOMER_ORDER_INFO_XML>
    <FetchCustomerInfoResponse xmlns="">
    <DJO_ONT_ACCOUNT_ORDERS>
    <DJO_ONT_ACCOUNT_ORDER ordered_date="24-APR-12" cust_po_number="PO1" order_number="123456" header_id="7777777"/>
    <DJO_ONT_ACCOUNT_ORDER ordered_date="19-APR-12" cust_po_number="PO2" order_number="4545454" header_id="888888"/>
    <DJO_ONT_ACCOUNT_ORDER ordered_date="09-APR-12" cust_po_number="PO3" order_number="56565656" header_id="999999"/>
    </FetchCustomerInfoResponse>
    </X_CUSTOMER_ORDER_INFO_XML>
    </OutputParameters></part></Invoke_new_get_customer_order_info_OutputVariable></messages>
    Any help is greatly appreciated as this is driving me nuts.
    Thanks

    Few modifications,
    1. Initialize your int count to 0, int count=0;
    2. Write count++; as the first statement in your for loop. 3. Remove count++; at the bottom.
    4. Add a hidden field to your form (after submit button, but before your </form> tag)
    <input type="hidden" name="qCount" value="<%=count%>">
    Now use this code,
    writeXML.jsp
    <%
    int qCount = Integer.parseInt(request.getParameter("qCount"));
    String home ="C:\\Tomcat\\FYProject\\lib\\";
    String filename = request.getParameter("file");
    String extension = ".xml";
    String filePath = home + filename + extension;
    BufferedWriter bw = new BufferedWriter(new FileWriter(filePath,true));
    bw.write("<mc_QuestionType>");
    bw.newLine();
    for(int count=0;count<qCount;count++) {
         String Tquestion = request.getParameter("questionText"+count);
         String answer1 = request.getParameter("choice_1"+count);
         String answer2 = request.getParameter("choice_2"+count);
         String answer3 = request.getParameter("choice_3"+count);
         String answer4 = request.getParameter("choice_4"+count);
         String Canswer = request.getParameter("cAnswer"+count);
         bw.write(" <questionText>" Tquestion "</questionText>");
         bw.newLine();
         bw.write(" <choice>" answer1 "</choice>");
         bw.newLine();
         bw.write(" <choice>" answer2 "</choice>");
         bw.newLine();
         bw.write(" <choice>" answer3 "</choice>");
         bw.newLine();
         bw.write(" <choice>" answer4 "</choice><br>");
         bw.newLine();
         bw.newLine();
         bw.write(" <answer>" Canswer "</answer>");
         bw.newLine();
         bw.write("</mc_QuestionType>");
         bw.close();
    %>Hope this works.
    Sudha

  • Printing ?xml version="1.0"..? tag in xmltype variable

    I created the xmltype "result" by using xmlelement and xmlforest functions in a select query.
    Now I need to add the "<?xml version="1.0" encoding="utf-8"?>" to the xmltype.
    I tried manipulating the clob (result.getclobval()) using dbms_lob.append() ,dbms_lob.write() and dbms_lob.writeappend() functions in various combinations,but nothing seems to work.
    Can anyone help me with this?
    Thanks,
    Aditi

    Hi,
    I want to strip it off because I am apppending the same in a Java Program.
    Please let me know how can it be done.
    Appreciate your inputs.
    Thanks,
    Dibya

  • Appending XML Node to XMLTYPE Variable

    Hi All,
    My Database Details,
    BANNER
    Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
    PL/SQL Release 9.2.0.1.0 - Production
    CORE 9.2.0.1.0 Production
    TNS for 32-bit Windows: Version 9.2.0.1.0 - Production
    NLSRTL Version 9.2.0.1.0 - Production
    SQL> var mycnt number
    SQL> exec :mycnt := 2
    SQL> declare
    xml xmltype := xmltype('
    <EMP>
    <NAME>
    </NAME>
    <SALARY>
    <DATE></DATE>
    <AMOUNT></AMOUNT>
    </SALARY>
    </EMP>');
    l_sal long := '<SALARY><DATE></DATE><AMOUNT></AMOUNT></SALARY>';
    l_str long;
    begin for i in 1 .. :mycnt
    loop
    l_str := l_str || l_sal;
    end loop;
    xml := xmltype(replace (xml.getstringval(), '</EMP>', l_str || '</EMP>'));
    dbms_output.put_line (xml.extract('.').getstringval());
    end;
    <EMP>
    <NAME/>
    <SALARY>
    <DATE/>
    <AMOUNT/>
    </SALARY>
    <SALARY>
    <DATE/>
    <AMOUNT/>
    </SALARY>
    <SALARY>
    <DATE/>
    <AMOUNT/>
    </SALARY>
    </EMP>
    This program is working fine. Consider the following scenario...
    My XML is like this,
    <ABC>
    <AB> -- First element
    <CCC></CCC>
    </AB>
    <AB> -- Second element
    <CCC></CCC>
    </AB>
    </ABC>
    Now i want to replicate the tag of <CCC></CCC>
    to 'N' TIMES from XPATH = /A/AB[1]/CCC and /A/AB[2]/CCC
    For example if N=3 then, the XML should be,
    <ABC>
    <AB>
    <CCC></CCC>
    <CCC></CCC>
    <CCC></CCC>
    </AB>
    <AB>
    <CCC></CCC>
    <CCC></CCC>
    <CCC></CCC>
    </AB>
    </ABC>
    Please provide me some Sample PLSQL code for this,
    Thanks in Advance,
    Simbhu

    not sure that this is waht you want - but maybe you find smth useful:
    SQL> set serveroutput on;
    SQL>
    SQL> declare str xmltype:=xmltype('<ABC><AB><CCC></CCC></AB><AB><CCC></CCC></AB><AB><CCC></CCC></AB></ABC>');
      2  begin
      3  for i in 1..2
      4  loop
      5  select InsertChildXML(str, '/ABC/AB['||i||']', 'CCC', XMLForest('' as "CCC",'' as "CCC")) into str from dual;
      6  end loop;
      7  dbms_output.put_line(str.extract('.').getstringval());
      8  end;
      9  /
    <ABC>
      <AB>
        <CCC/>
        <CCC/>
        <CCC/>
      </AB>
      <AB>
        <CCC/>
        <CCC/>
        <CCC/>
      </AB>
      <AB>
        <CCC/>
      </AB>
    </ABC>
    PL/SQL procedure successfully completed
    SQL>

  • Selective extraction from an xmltype variable

    I have a fragment of XML -
    <Unit name="MAIN UNIT">
    <Ops event_type="U1" cause_code="7050" begin_time="2003-06-13T09:38:00">Broken restoring cable</Ops>
         <Ops event_type="GE" cause_code="0001" begin_time="2003-06-03T07:07:03"/>
    <Generation begin_time="2003-06-13T00:00:00" end_time="2003-06-13T23:59:59" mwh_produced="229.00" mwh_consumed="0.00"/>
    </Unit>
    I am trying to extract just the text of an "Ops" fragment. In the above case, the first would be "Broken restoring cable" and the second would be NULL. Using
    v_belement.extract('/Ops').getStringVal()
    inside of a loop through the array gives me the entire fragment. How can I get just the text?
    Bill

    Bill,
    Try extractValue instead of extract.
    Bharathi

  • Is it possible to add variable defined as xmltype to an xmldom node?

    Hi,
    I'm trying to produce a complex XML document that doesn't lend itself well to using SQL XML functions (xmlagg, xmlelement, etc.) because various disparate data needs to be pulled together via seperate queries and then stuck into the final document in the correct spots.
    So I've resorted to using the convoluted pl/sql xmldom functions. What I'm wondering though is if it is possible to take data in an xmltype variable and somehow append it as a node within my xml document? Something as in the following pseudo code:
    begin
    doc := xmldom.newDOMDocument;
    main_node := xmldom.makeNode (doc);
    select xmlelement("Address",...) -- more xmlelements containing related address info (street, city, etc.)
    into l_address
    from ...;
    new_node := xmldom.appendChild (main_node, xmldom.makeNode (l_address));
    end;
    If possible, this would save me a tremendous amount of time from having to code every element and attributes via the xmldom functions.
    Thanks,
    Alan

    I've done the same scenario you are describing, shove XML defined in an XMLType into a DOMDocument. I munged the code to hide system specific references so the code works, just not as pasted here. The document is being built in o_response_doc and goes after the node previously built in l_rsp_msg_nd. The input is l_xmltype. May be a better way but I never found one and came up with this based on the Oracle documentation and trial and error.
        -- Convert the XMLType to a DOMDocument so we can extract the needed node
        --  and insert it into the response DOMDocument
        l_temp_domdoc := dbms_xmldom.newdomdocument(l_xmltype);
        l_inq_nodelist := dbms_xmldom.getelementsbytagname(l_temp_domdoc,
                                                           'DesiredXMLTypeNodeName');
        l_inq_nl_len := xmldom.getlength(l_inq_nodelist);
        IF l_inq_nl_len > 0 THEN
           -- Take the node above and adopt it into the response document
           l_temp2_nd := dbms_xmldom.importNode(o_response_doc,
                                                dbms_xmldom.item(l_inq_nodelist, 0),
                                                TRUE);
           -- Remove the a: namespace that was autoadded.  (this was defined in the l_xmltype XML)
           dbms_xmldom.removeattribute(dbms_xmldom.makeelement(l_temp2_nd),
                                       <ns_pfx>,
                                       <ns_uri>);
           -- Put the node in the correct position in the response document                                          
           l_temp2_nd := xdb.dbms_xmldom.appendChild(l_rsp_msg_nd, l_temp2_nd);
        END IF;
        dbms_xmldom.freeDocument(l_temp_domdoc);

  • UpdateXML and Trigger

    Hello,
    i need a trigger, that validate a XML-Document against the XSD-Schema. If the validation is OK, then a sequential number and the actual date should be insertet in the xml-document.
    This is the trigger i tried (this trigger works - but is it correct? Because this is my first trigger i tried):
    create or replace
    TRIGGER VALIDATE_ID_AUTOMARKE
    before insert or Update on XML_AUTOMARKE
    for each row
    declare
    -- XMLType variable to hold the current(to be inserted) XMLType record.
    XMLDATA xmltype;
    tmpxml XMLType;
    begin
    XMLDATA := :new.sys_nc_rowinfo$;
    xmltype.schemavalidate(XMLDATA);
    IF XMLDATA.isSchemaValid('http://localhost/home/user/xsd/automarkeAlleine.xsd') = 1 THEN
    IF xmldata.existsnode('/bookstore/metadata/values/id') = 1 THEN
    -- Update the <Date> element value to sysdate
    SELECT UPDATEXML(xmldata, '/bookstore/metadata/values/id','<id>'|| to_char(SEQ_UNIQUEID_ON_AUTOM_ALLLEIN.nextval) || '</id>')
    INTO tmpxml FROM dual;
    -- Assign the updated XML document to the current record.
    :new.sys_nc_rowinfo$ := tmpxml;
    END IF;
    END IF;
    end;
    But when i put a second updatexml-funktion in the select an error appears. I tried for example this:
    SELECT UPDATEXML(xmldata, '/bookstore/metadata/values/id','<id>'|| to_char(SEQ_UNIQUEID_ON_AUTOM_ALLLEIN.nextval) || '</id>'), UPDATEXML(xmldata, '/bookstore/metadata/values/datum',
    '<datum>'|| to_char(sysdate, 'DD-MON-YYYY') || '</datum>')
    INTO tmpxml FROM dual;
    How can i do this?
    Thank you very much
    George

    i think i have the solution:
    create or replace
    TRIGGER VALIDATE_ID_AUTOMARKE
    before insert or Update on XML_AUTOMARKE
    for each row
    declare
    -- XMLType variable to hold the current(to be inserted) XMLType record.
    XMLDATA xmltype;
    tmpxml XMLType;
    begin
    XMLDATA := :new.sys_nc_rowinfo$;
    xmltype.schemavalidate(XMLDATA);
    IF XMLDATA.isSchemaValid('http://localhost/home/user/xsd/automarkeAlleine.xsd') = 1 THEN
    IF xmldata.existsnode('/bookstore/metadata/values/id') = 1 THEN
    -- Update the <Date> element value to sysdate
    SELECT UPDATEXML(xmldata, '/bookstore/metadata/values/id','<id>'|| to_char(seq_uniqueID_on_XML_BOOKSTORE.nextval) || '</id>', '/bookstore/metadata/values/datum','<datum>'|| to_char(sysdate, 'YYYY-MM-DD HH24:MI:SS') || '</datum>')
    INTO tmpxml FROM dual;
    -- Assign the updated XML document to the current record.
    :new.sys_nc_rowinfo$ := tmpxml;
    END IF;
    END IF;
    end;
    is this trigger ok? it works fine but i´m not sure (i can´t believe) that this is the optimal solution?

  • (urgent) How to make sumarize query against XMLType?

    Hello,
    i have xml document like this
    <List>
    <Item>
    <A>10</A>
    <B>554</B>
    <C>25.5.2005</C>
    </Item>
    <Item>
    <A>20</A>
    <B>49</B>
    <C>26.5.2005</C>
    </Item>
    <Item>
    <A>30</A>
    <B>184</B>
    <C>27.5.2005</C>
    </Item>
    </List>
    in xmltype variable (not table column) and i need e.g. sum (or count or something like that) values in xpath /List/Item/B in one document.
    Is there some quick and elegant way to do this?
    Thanks for quick help.

    Maybe the below will help.
    Did you look at building a view over the xmltype extracting the values into a relational type view, then using the view to sum up the values.
    Jonthan Gennick has an article on the Oracle OTN website with the below code.
    CREATE VIEW cd_master (Title, Artist, Website, Description) AS
    SELECT extractValue(value(x),'/CD/Title'),
    extractValue(value(x),'/CD/Artist'),
    extractValue(value(x),'/CD/Website'),
    extractValue(value(x),'/CD/Description')
    FROM CD331_TAB x;
    CREATE INDEX by_artist ON CD331_TAB x (
    extractValue(value(x),'/CD/Artist'));
    ANALYZE TABLE cd331_tab COMPUTE STATISTICS FOR TABLE;
    ANALYZE INDEX by_artist COMPUTE STATISTICS;

  • [11g] most efficient way to calculate size of xmltype type column

    I need to check the current size of some xmltype column in a BIU trigger.
    I don't think it's good to use
      length(:new.xml_data.GetStringVal());
    or
      dbms_lob.GetLength(:new.xml_data.GetClobVal());
    What's the most efficient way to get the storage size?
    I don't need the string serialized size.
    It could also be the internal storage size (incl. administration data overhead).
    - thanks!
    regards,
    Frank

    > May I ask for what reason you need to know it?
    I need to handle very large XML document output, which currently hits the internal xmltype limitation of 4GByte, when aggregating XML document fragments for this.
    > You'll get a relevant answer if you give us relevant information :
    > - exact db version
    SELECT * FROM PRODUCT_COMPONENT_VERSION;
    product
    version
    status
    1
    NLSRTL
    11.2.0.3.0
    Production
    2
    Oracle Database 11g Enterprise Edition
    11.2.0.3.0
    64bit Production
    3
    PL/SQL
    11.2.0.3.0
    Production
    4
    TNS for Linux:
    11.2.0.3.0
    Production
    > - DDL of your table
    > XML stored as XMLType datatype can use different storage models, depending on the version.
    I don't use dedicated storage clause.
    But i am hitting the problem already for aggregation into some xmltype variable in PL/SQL
    - BEFORE writing back to a result table.
    Can i avoid such problems, when writing to a table DIRECTLY w/o intermediate xmltype PL/SQL variable
    - depending on the storage clause?
    The reason why asking how to get the size of some xmltype (in table column and/or in PL/SQL variable) is, that i am thinking of a threshold detection.
    In case threshold is reached: outsource XML fragment so far to some separate CLOB storage, and insert a smaller meta-information reference representing that in the output document.
    Finally leave up to the client system to use <xs:include> (or alike) to construct the complete document.
    rgds,
    Frank

  • XMLType.extract cannot show special French characters in select statement

    Hi,
    The (e acute) é characters get garbled when they are retrieved from the
    XMLType column of a regular table.
    How can we fix to get (e acute) é characters properly?
    We both tried setting "setenv NLS_LANG French_France.WE8ISO8859P1" and
    "setenv NLS_LANG French_France.WE8DEC" before loading the table.
    Database version:
    SQL> select * from v$version;
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - Production
    PL/SQL Release 11.2.0.2.0 - Production
    CORE    11.2.0.2.0      Production
    TNS for Linux: Version 11.2.0.2.0 - Production
    NLSRTL Version 11.2.0.2.0 - ProductionThe sample test case is as follows:
    --connect to any schema where you can store XMLType
    set long 2000;
    set pagesize 2000;
    set serveroutput on;
    --delete from test;
    drop table test;
    create table test (id number, xmldata XMLType);
    declare
    featureDescriptorXML  CLOB;
    xml_type XMLType;
    new_xml_type XMLType;
    myName varchar2(100);
    myName2 varchar2(100);
    myName3 varchar2(100);
    stmt varchar2(4000);
    begin
    featureDescriptorXML :=
    '<?xml version="1.0" encoding="UTF-8"?>' ||
    '<abc:TheFeature xmlns:' || 'de' || '="' || 'http://abc.klmno.org/fghde' || '" xmlns:abc="http://www.ghijklmn.net/abc"' ||
    ' xmlns:xyz="http://www.ghijklmn.net/xyz">' ||
    '<abc:Name>de:MyGénérique</abc:Name>' ||
    '</abc:TheFeature>';
    xml_type := xmltype(featureDescriptorXML);
    myName := xml_type.extract('/abc:TheFeature/abc:Name/text()', 'xmlns:abc="http://www.ghijklmn.net/abc"').getStringVal();
    dbms_output.put_line('abc:Name value stored in VARCHAR2 variable from XMLType variable is ' || myName);
    -- can show French chars
    insert into test(id, xmldata) values(20, xml_type);
    stmt := 'select t.xmldata.extract(''/abc:TheFeature/abc:Name/text()'', ''xmlns:abc="http://www.ghijklmn.net/abc"'').getStringVal() from test t';
    execute immediate stmt into myName2;
    dbms_output.put_line('abc:Name value stored in VARCHAR2 variable from XMLType column in 2nd version is ' || myName2);
    -- cannot show French chars
    stmt := 'select  t.xmldata from test t';
    execute immediate stmt into new_xml_type;
    myName3 := new_xml_type.extract('/abc:TheFeature/abc:Name/text()', 'xmlns:abc="http://www.ghijklmn.net/abc"').getStringVal();
    dbms_output.put_line('abc:Name value stored in VARCHAR2 variable from first XMLType column and then from XMLType variable in 3rd version is ' || myName3);
    -- cannot show French chars
    end;
    select t.xmldata.extract('/abc:TheFeature/abc:Name/text()', 'xmlns:abc="http://www.ghijklmn.net/abc"').getStringVal()
    from test t;
    -- Cannot show French chars
    select t.xmldata.extract('/abc:TheFeature/abc:Name/text()', 'xmlns:abc="http://www.ghijklmn.net/abc"').getStringVal() "myname"
    from test t;
    -- Cannot show French chars
    select t.xmldata.getCLOBVal() from test t;
    -- Cannot show French chars
    select t.xmldata from test t;
    -- Can show French charsOutput is as follows with setenv NLS_LANG French_France.WE8ISO8859P1
    and NLS_DATABASE_PARAMETERS are as follows:
    SQL> select * from nls_database_parameters;
    PARAMETER                      VALUE
    NLS_LANGUAGE                   AMERICAN
    NLS_TERRITORY                  AMERICA
    NLS_CURRENCY                   $
    NLS_ISO_CURRENCY               AMERICA
    NLS_NUMERIC_CHARACTERS         .,
    NLS_CHARACTERSET               WE8DEC
    NLS_CALENDAR                   GREGORIAN
    NLS_DATE_FORMAT                DD-MON-RR
    NLS_DATE_LANGUAGE              AMERICAN
    NLS_SORT                       BINARY
    NLS_TIME_FORMAT                HH.MI.SSXFF AM
    PARAMETER                      VALUE
    NLS_TIMESTAMP_FORMAT           DD-MON-RR HH.MI.SSXFF AM
    NLS_TIME_TZ_FORMAT             HH.MI.SSXFF AM TZR
    NLS_TIMESTAMP_TZ_FORMAT        DD-MON-RR HH.MI.SSXFF AM TZR
    NLS_DUAL_CURRENCY              $
    NLS_COMP                       BINARY
    NLS_LENGTH_SEMANTICS           BYTE
    NLS_NCHAR_CONV_EXCP            FALSE
    NLS_NCHAR_CHARACTERSET         AL16UTF16
    NLS_RDBMS_VERSION              11.2.0.2.0
    20 ligne(s) sélectionnée(s).
    Table creé.
    abc:Name value stored in VARCHAR2 variable from XMLType variable is
    de:MyGénérique
    abc:Name value stored in VARCHAR2 variable from XMLType column in 2nd version is
    de:MyGénérique
    abc:Name value stored in VARCHAR2 variable from first XMLType column and then
    from XMLType variable in 3rd version is de:MyGénérique
    Procdure PL/SQL terminée avec succès.
    T.XMLDATA.EXTRACT('/ABC:THEFEATURE/ABC:NAME/TEXT()','XMLNS:ABC="HTTP://WWW.GHIJK
    de:MyGénérique
    myname
    de:MyGénérique
    T.XMLDATA.GETCLOBVAL()
    <?xml version="1.0" encoding="DEC-MCS"?>
    <abc:TheFeature xmlns:de="http://abc.klmno.org/fghde" xmlns:abc="http://www.ghij
    klmn.net/abc" xmlns:xyz="http://www.ghijklmn.net/xyz">
      <abc:Name>de:MyGénérique</abc:Name>
    </abc:TheFeature>
    XMLDATA
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <abc:TheFeature xmlns:de="http://abc.klmno.org/fghde" xmlns:abc="http://www.ghij
    klmn.net/abc" xmlns:xyz="http://www.ghijklmn.net/xyz">
      <abc:Name>de:MyGénérique</abc:Name>
    </abc:TheFeature>We also tried setting NLS_CHARACTERSET to AL32UTF8
    via ALTER DATABASE CHARACTER SET,
    and then shutting down the database and restarting it.
    But, that did not help.
    Thanks

    Good to hear then, you have not yet got a SR on your hands.
    One of the reasons I hate NLS issues is that me first one had to do with an client browser/ application server and database setup that involved not equal settings between the app.server and the database. Always, always fully check that the app.server (on all fronts) have the same NLS settings as the database so that you avoid unnecessary conversion between the middle tier and the database tier. "On all fronts" means, as I once painfully discovered, possible NLS settings in a registry, app.server configuration file, java application in the JVM, etc, etc, etc. Another issue is that JDBC drivers, AFAIK, have issues with "opaque data types" (http://en.wikipedia.org/wiki/Opaque_data_type) like "XMLTYPE" so, to be sure, I would advice to transport the "XML content" in a data type which is supported much longer like "CLOB". In such cases, NLS conversions shouldn't take place. There are exceptions of course, one I can think of right now is when you move Binary XML content via the binary xml transport method (can't remember right now the proper java classes to use for this) between the client and server to obtain performance gains due to among others less and more efficient data transport across the network and avoiding validation and post parse overhead during the Binary XML content handling in the database.
    Looked it up anyway :-) the following is part of the 11.2 Oracle XDK
    Binary XML usage with Java:
    http://download.oracle.com/docs/cd/E14072_01/appdev.112/e10708/adx_j_xmlbin.htm#BAJFBGGB
    Scalable DOM:
    http://download.oracle.com/docs/cd/E14072_01/appdev.112/e10708/adx_j_parser.htm#CCHGIADJ

  • How to assign to variable from XML type values with extract function?

    Hi ,
    I have XMLTYPE variable LeXml having below record
    <?xml version="1.0" encoding="utf-8"?>
    <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Body>
    <AddListing xmlns="http://www.christielites.com/">
    <sComCode>string</sComCode>
    <sLocCode>string</sLocCode>
    <dStart>dateTime</dStart>
    <dEnd>dateTime</dEnd>
    <sEcode>string</sEcode>
    <iAvail>int</iAvail>
    <iOwned>int</iOwned>
    <sPostTrans>string</sPostTrans>
    </AddListing>
    </soap:Body>
    </soap:Envelope>
    I want to get sEcode value string into one varialbe using extract function or alternate?
    can any one give me syntax fro it?
    I tried with Mstring:=LeXml.extract('AddListing/scomcode/text()').getStringval(); but iam getting error
    ERROR at line 1:
    ORA-31011: XML parsing failed
    ORA-19202: Error occurred in XML processing
    LPX-00601: Invalid token in: 'soap:Envelope/text()'
    ORA-06512: at "SYS.XMLTYPE", line 111
    ORA-06512: at "BLUEWATER.CREATELERESPONSELOG", line 12
    ORA-06512: at line 1
    Please guide Me..

    Hi Ravi kumar,
    I have similar type of problem like above . My xml file is like below:
    <doSingleRecordResponse xmlns="urn:mdWebService">
    <doSingleRecordResult xsi:type="ResponseRecord" id="1" version="2.30" action="Response" timeout="10" timestamp="12-17-2009" transmissionReference="ABCDEF" TimeToProcess="31.25" xmlns:xsi="http://www
    .w3.org/2001/XMLSchema-instance">
    <CustomerCredentials>
    <CustomerID>111111</CustomerID>
    </CustomerCredentials>
    <ServiceResult>
    <ErrorCode> </ErrorCode>
    <ErrorDesc>OK;</ErrorDesc>
    </ServiceResult>
    <Address version="2.30">
    <Faults count="0"/>
    <Result>
    <ErrorCode> </ErrorCode>
    <ErrorDesc>OK</ErrorDesc>
    <StatusCode>9</StatusCode>
    <StatusD
    esc>(U.S.) The address was fully coded.</StatusDesc>
    </Result>
    <Company/>
    <Urbanization>
    <Name/>
    <Code/>
    </Urbanization>
    <Type>
    <String>Highrise</String>
    <Code>H</Code>
    </Type>
    <Street>XXXXXXXXXXXXX</Street>
    <Street2/>
    <Suite/>
    <PrivateMailBox/>
    <CarrierRoute>C048</CarrierRoute>
    <Lacs> </Lacs>
    <LacsLink>
    <LacsStatusCode/>
    <LacsReturnCode/>
    </LacsLink>
    <DeliveryPointCode>99</DeliveryPointCode>
    <DeliveryPointCheckDigit>6</DeliveryPointCheckDigit>
    <DPV>
    <Footnotes/>
    <CMRA/>
    <AddressStatus/>
    </DPV>
    <DeliveryIndicator>
    <Code/>
    </DeliveryIndicator>
    <City>
    <Name>String</Na
    me>
    <Abbreviation>Memphis</Abbreviation>
    </City>
    <County>
    <Name>String</Name>
    <Fips>41111</Fips>
    </County>
    <State>
    <Name>Tennessee</Name>
    <Abbreviation>TN</Abbreviation>
    </State>
    <Zip>
    <Type> </Type>
    <Zip5>38111</Zip5>
    <Plus4>1111</Plus4>
    </Zip>
    <GeoCode>
    <Latitude/>
    <Longitude/>
    </GeoCode>
    <TimeZone>
    <Name/>
    <Code/>
    </TimeZone>
    <Msa>
    <Code/>
    </Msa>
    <Pmsa>
    <Code/>
    </Pmsa>
    <Census>
    <Block/>
    <Tract/>
    </Census>
    <CongressionalDistrict>
    <Code/>
    </CongressionalDistrict>
    <Parsed>
    <StreetName/>
    <AddressRange/>
    <Suffix/>
    <Direction>
    <Post/>
    <Pre/>
    </Direction>
    <Suite>
    <Name/>
    <Range/>
    </Suite>
    <PrivateMailBox>
    <Name/>
    <Range/>
    </PrivateMailBox>
    <Garbage/>
    </Parsed>
    <Country>
    <Abbreviation>US</Abbreviation>
    <Name>United St
    ates of America</Name>
    </Country>
    </Address>
    <Telephone version="" action="">
    <Result>
    <ErrorCode/>
    <ErrorDesc/>
    <StatusCode/>
    <StatusDesc/>
    </Result>
    <Number/>
    <PhoneAreaCode/>
    <NewAreaCode/>
    <Prefix/>
    <Suffix/>
    <Extension/>
    <City>
    <Name/>
    </City>
    <State>
    <Name/>
    <Abbreviation/>
    </State>
    <GeoCode>
    <Latitude/>
    <Longitude/>
    </GeoCode>
    <TimeZone>
    <Name/>
    <Code/>
    </TimeZone>
    <Msa>
    <Code/>
    </Msa>
    <Pmsa>
    <Code/>
    </Pmsa>
    <County>
    <Name/>
    <Fips/>
    </County>
    <Country>
    <Abbreviation/>
    <Name/>
    </Country>
    </Telephone>
    <Name version="" action="">
    <Result>
    <ErrorCode/>
    <ErrorDesc/>
    <StatusCode/>
    <StatusDesc/>
    </Result>
    <Company/>
    <Prefix/>
    <Suffix/>
    <Full/>
    <First/>
    <Middle/>
    <Last/>
    <Gender/>
    </Name>
    </doSingleRecordResult>
    </doSingleRecordResponse>
    This is the response i got from a webservice , from this i need to extract customer id .
    I tried like this :
    response := UTL_DBWS.invoke ( l_call,request);
    if RESPONSE.extract('/doSingleRecordResponse/doSingleRecordResult/CustomerCredentials/CustomerID/text()','xmlns:xsi="http://www
    .w3.org/2001/XMLSchema-instance" xmlns="urn:mdWebService"') is not NULL
    then
    errorcode :=RESPONSE.extract('/doSingleRecordResponse/doSingleRecordResult/CustomerCredentials/CustomerID/text()','xmlns:xsi="http://www
    .w3.org/2001/XMLSchema-instance" xmlns="urn:mdWebService"').getStringVal;
    end if;
    I am getting null value into errorcode,
    Can youplease let me know what i am doing wrong?
    Thanks

  • Convert XMLTYPE to VARCHAR2 or CLOB?

    Does anyone know how to convert an XMLTYPE variable to VARCHAR2 or CLOB? I am using the XMLELEMENT function to select XML into an XMLTYPE variable (VARCHAR2 and CLOB will not accept xml from this function). But I would like to convert the xml in the XMLTYPE variable to VARCHAR2 or CLOB. Can anyone please tell me how to do this? The reason is that I would like to call this procedure from MS ADO.
    Anthony Sneed
    email: [email protected]

    Hi,
    But I would like to convert the xml in the XMLTYPE variable to VARCHAR2 or CLOB.You can select XMLType data using PL/SQL or Java. You can also use the getClobVal(), getStringVal(), or getNumberVal() functions to retrieve XML as a CLOB, VARCHAR, or NUMBER, respectively.
    Example 4-18 Selecting XMLType Columns using getClobVal()
    This example shows how to select an XMLType column using SQL*Plus:
    SET long 2000
    SELECT e.poDoc.getClobval() AS poXML
    FROM po_xml_tab e;
    POXML
    <?xml version="1.0"?>
    <PO pono="2">
    <PNAME>Po_2</PNAME>
    <CUSTNAME>Nance</CUSTNAME>
    <SHIPADDR>
    <STREET>2 Avocet Drive</STREET>
    <CITY>Redwood Shores</CITY>
    <STATE>CA</STATE>
    </SHIPADDR>
    </PO>
    Look into the documentation: Oracle9i XML Database Developer's Guide - Oracle XML DB for more details.
    Hope that helps.
    OTN team@IDC

Maybe you are looking for

  • DVD-RW does not play on computer

    I have recently created three separate slideshows, each containing 3 submenus with a total of 600 photos in the three separate shows. I have iDVD 6 which created the shows. I burned the first one which I believe is 1 GB onto a DVD-RW. I assumed I wou

  • Proper syntax of the file name to attach files in FNDATTCH.fmb

    Can you please tell me the proper syntax of the file name to attach files in FNDATTCH.fmb ? i am not able to open attached document if it contains & in the file name..So i wanted to know the rules to give the file name

  • CSV format file through Report scripts.

    Hello Gurus - In hyperion report scripts we can use the "Tabdelimited" syntax to produce the extract where the columns are separated by tabs. I was wondering if there is a way to get the columns separated by "Comma" instead of Tabs through the report

  • Budget problem

    Hi PS Guru's, there is a WBS element i.e A , which budgeted and availability control active. I have purchased some raw material against WBS element. system check the budget and also consume the budget. now we are creting a production order and assign

  • A lot of problems with my xperia z2 :\

    So I bought my xperia z2 like 2 months back, and ever since i bought it, it kept restarting over and over without a warning or anything. But sometimes this problem stops but comes back later -.- . anyway, so yesterday i went to a swimming pool and re