Nested hierachy query to xml

<pre>
To use dynatree(https://code.google.com/p/dynatree/) I want the result to be in the xml form.
but the result is not what I want.
can anybody help me?
SELECT
XMLELEMENT("div",xmlattributes('tree' AS "id"),
(SELECT DBMS_XMLGEN.getXMLType(
DBMS_XMLGEN.newContextFromHierarchy('
SELECT LEVEL,
case
when CONNECT_BY_ISLEAF = 0 then
XMLELEMENT("ul", XMLELEMENT("li", xmlattributes(empno AS "id"), ename))
when CONNECT_BY_ISLEAF = 1 then
XMLELEMENT("li", xmlattributes(empno AS "id"), ename)
end
FROM emp
START WITH mgr is null
CONNECT BY PRIOR empno = mgr '
) FROM DUAL
)) XMLDOC
FROM DUAL;
CURRENT RESULT
&lt;div id="tree"&gt;&lt;ul&gt;
&lt;li id="7839"&gt;KING&lt;/li&gt;
&lt;ul&gt;
&lt;li id="7566"&gt;JONES&lt;/li&gt;
&lt;ul&gt;
&lt;li id="7788"&gt;SCOTT&lt;/li&gt;
&lt;li id="7876"&gt;ADAMS&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li id="7902"&gt;FORD&lt;/li&gt;
&lt;li id="7369"&gt;SMITH&lt;/li&gt;
&lt;/ul&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li id="7698"&gt;BLAKE&lt;/li&gt;
&lt;li id="7499"&gt;ALLEN&lt;/li&gt;
&lt;li id="7521"&gt;WARD&lt;/li&gt;
&lt;li id="7654"&gt;MARTIN&lt;/li&gt;
&lt;li id="7844"&gt;TURNER&lt;/li&gt;
&lt;li id="7900"&gt;JAMES&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li id="7782"&gt;CLARK&lt;/li&gt;
&lt;li id="7934"&gt;MILLER&lt;/li&gt;
&lt;/ul&gt;
&lt;/ul&gt;
&lt;/div&gt;
DESIRED RESULT
&lt;ul&gt;
&lt;li id="7839"&gt;KING
&lt;ul&gt;
&lt;li id="7566"&gt;JONES
&lt;ul&gt;
&lt;li id="7788"&gt;SCOTT
&lt;ul&gt;
&lt;li id="7876"&gt;ADAMS&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li id="7902"&gt;FORD
&lt;ul&gt;
&lt;li id="7369"&gt;SMITH&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li id="7698"&gt;BLAKE
&lt;ul&gt;
&lt;li id="7499"&gt;ALLEN&lt;/li&gt;
&lt;li id="7521"&gt;WARD&lt;/li&gt;
&lt;li id="7654"&gt;MARTIN&lt;/li&gt;
&lt;li id="7844"&gt;TURNER&lt;/li&gt;
&lt;li id="7900"&gt;JAMES&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li id="7782"&gt;CLARK
&lt;ul&gt;
&lt;li id="7934"&gt;MILLER&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
</pre>
Edited by: kang on Mar 5, 2013 8:27 PM

DBMS_XMLGEN.newContextFromHierarchy can only append children elements to their parents while walking the hierarchical tree down.
That means if a parent is :
<ul><li>KING</li></ul>then children are added to the &lt;ul> element, not to &lt;li> as you require.
Maybe you can explore one of the other solutions described here : http://odieweblog.wordpress.com/2011/11/24/how-to-generate-a-recursive-xml-structure/
Example with XQuery (requires 10.2) :
SQL> SELECT XMLSerialize(DOCUMENT
  2           XMLQuery(
  3           'declare function local:getEmployees($emps as element(ROW)*, $mgr as xs:integer?) as element()*
  4            {
  5              let $li :=
  6                for $i in $emps
  7                where $i/MGR = $mgr
  8                   or ( empty($mgr) and not(exists($i/MGR)) )
  9                order by $i/EMPNO
10                return
11                  <li id="{$i/EMPNO}">
12                  {
13                     $i/ENAME/text()
14                   , local:getEmployees($emps, $i/EMPNO)
15                  }
16                  </li>
17              return if ($li) then <ul>{$li}</ul> else ()
18            }; (: :)
19            <div id="tree">
20            {
21              local:getEmployees(fn:collection("oradb:/SCOTT/EMP")/ROW, ())
22            }
23            </div>'
24           returning content
25           )
26           AS CLOB INDENT
27         )
28  FROM dual
29  ;
XMLSERIALIZE(DOCUMENTXMLQUERY(
<div id="tree">
  <ul>
    <li id="7839">KING<ul>
        <li id="7566">JONES<ul>
            <li id="7788">SCOTT<ul>
                <li id="7876">ADAMS</li>
              </ul>
            </li>
            <li id="7902">FORD<ul>
                <li id="7369">SMITH</li>
              </ul>
            </li>
          </ul>
        </li>
        <li id="7698">BLAKE<ul>
            <li id="7499">ALLEN</li>
            <li id="7521">WARD</li>
            <li id="7654">MARTIN</li>
            <li id="7844">TURNER</li>
            <li id="7900">JAMES</li>
          </ul>
        </li>
        <li id="7782">CLARK<ul>
            <li id="7934">MILLER</li>
          </ul>
        </li>
      </ul>
    </li>
  </ul>
</div>

Similar Messages

  • Passing parameters for a query throught XML and capturing response in the same

    Hi All,
    I have defined a RequestParameters object and i am passing paramerts for a query through XML and trying to capture the result in the same and send back to the source. In this case i am send XML from excel.
    Below is my XML format.
    <?xml version="1.0" encoding="utf-8"?>
    <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
    <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <Insert xmlns="http://tempuri.org/">
    <dataContractValue>
    <dsRequest>
    <dsRequest>
    <SOURCE></SOURCE>
    <ACTION>Insert</ACTION>
    <RequestParams>
    <RequestParams>
    <ACC_NO>52451</ACC_NO>
    <EMP_CITY>HYD</EMP_CITY>
    <EMP_NAME>RAKESH</EMP_NAME>
    <EMP_CONTACT>99664</EMP_CONTACT>
    <EMP_JOM>NOV</EMP_JOM>
    <EMP_SALARY>12345</EMP_SALARY>
    </RequestParams>
    <RequestParams>
    <ACC_NO>52452</ACC_NO>
    <EMP_CITY>HYD</EMP_CITY>
    <EMP_NAME>RAKESH</EMP_NAME>
    <EMP_CONTACT>99664</EMP_CONTACT>
    <EMP_JOM>NOV</EMP_JOM>
    <EMP_SALARY>12345</EMP_SALARY>
    </RequestParams>
    </RequestParams>
    </dsRequest>
    <dsRequest>
    <SOURCE></SOURCE>
    <ACTION>Update</ACTION>
    <RequestParams>
    <RequestParams>
    <ACC_NO>52449</ACC_NO>
    <EMP_CITY>HYD1</EMP_CITY>
    <EMP_NAME>RAKESH1</EMP_NAME>
    <EMP_SALARY>1345</EMP_SALARY>
    </RequestParams>
    <RequestParams>
    <ACC_NO>52450</ACC_NO>
    <EMP_CITY>HYDer</EMP_CITY>
    <EMP_NAME>RAKEH</EMP_NAME>
    <EMP_SALARY>1235</EMP_SALARY>
    </RequestParams>
    </RequestParams>
    </dsRequest>
    </dsRequest>
    </dataContractValue>
    </Insert>
    </s:Body>
    </s:Envelope>
     Where i have a List of dsRequest and RequestParams, where i can send any number of requests for Insert,Update. I have two a XML element defined in RequestParams "RowsEffected","error" where the result will be caputred and is updated
    to the response XML.
    I have 6 defined in RequestParams
    EMP_SALARY(int),ACC_NO(int),EMP_CITY(string),EMP_NAME(string),EMP_CONTACT(string),EMP_JOM(string)
    My Question is:
    When i am trying to build response XML with the following code, the parameters which are not given in the Request XML are also appearing in the Response.
                    ResponseParams.Add(
    newdsResponse()
                        ACTION = OriginalParams[a].ACTION,
                        SOURCE = OriginalParams[a].SOURCE,
                        Manager = OriginalParams[a].Manager,
                        RequestParams = OriginalParams[a].RequestParams
    Where the OriginalParams is dsRequest
    Ex: In my update query i will only send three parameters, but in my response building with ablove code, i am getting all the variables defined as INT in the RequestParameters.
    Is there any way i can avoid this and build response with only the parameters given in the Request ??
    Appreciate ur help..Thanks
    Cronsey.

    Hi Kristin,
    My project is, User will be giving the parameters in the excel, and using VBA, the values are captured and an XML is created in the above mentioned format and is send to web service for the Insert/Update.
    I created a webservice which reads the values from <datacontract> and it consist of list of <dsRequests> where any number of Insert/Upate commands can be executed, with in which it contains a list of <RequestParams> for multiple insertion/Updation.
    //function call
    OriginalParams = generator.Function(query, OriginalParams);
    where OriginalParams is List<dsRequest>
    //inside function
    command.Parameters.Add()// parameters adding
    int
    val = command.ExecuteNonQuery();
    after the execution,an XML element is added for the response part.and it is looped for all the RequestParams.
    OriginalParams[i].Result.Add(
    newResult()
    { ERROR = "No Error",
    ROWS_EFFECTEFD = 1 });
    //once all the execution is done the response building part
    for(inta
    = 0; a < OriginalParams.Count; a++)
                    ResponseParams.Add(
    newdsResponse()
                      Result = OriginalParams[a].Result
    QUEST: When i am trying to build response XML with the following code, the parameters which are not given in the Request XML are also appearing in the Response.
    Ex: In my update query i will only send three parameters, but in my response building with ablove code, i am getting all the variables defined as INT in the RequestParameters.
    Is there any way i can avoid this and build response with only the parameters given in the Request ??
    Appreciate ur help..Thanks
    Cronsey.

  • Can we generate the output of SQL Query in XML format ..

    Hi Team,
    Can we generate an XML doc for an SQL Query.
    I've seen in SQL Server 2000.It is generating the output of an SQL Query in xml format.
    select * from emp for xml auto
    The output looks like
    <emp EMPNO="7369" ENAME="SMITH" JOB="CLERK" MGR="7902" HIREDATE="1980-12-17T00:00:00" SAL="2800" DEPTNO="20"/><emp EMPNO="7370" ENAME="SMITH" JOB="CLERK" MGR="7902" HIREDATE="1980-12-17T00:00:00" SAL="2800" DEPTNO="10"/>

    Just a little bit of short hand.
    Get the XML out of your database, via HTTP
    Of course the easiest method is just to return an XMLType from a stored procedure and let the calling routine figure out what to do with it. Instead
    of that way though, I'll show you how to do it via HTTP. It's all completely built into 10g and is super easy to use.
    CREATE OR REPLACE VIEW emps_and_depts AS
    SELECT e.employee_id AS "EmployeeId",
    e.last_name AS "Name",
    e.job_id AS "Job",
    e.manager_id AS "Manager",
    e.hire_date AS "HireDate",
    e.salary AS "Salary",
    e.commission_pct AS "Commission",
    XMLFOREST (
    d.department_id AS "DeptNo",
    d.department_name AS "DeptName",
    d.location_id AS "Location"
    ) AS "Dept"
    FROM employees e, departments d
    WHERE e.department_id = d.department_id
    Some people hear web and immediately start salivating about security issues. Let me address that quickly. Just because you have the HTTP and/or
    FTP servers running in the database, that does not mean you have a security problem. For one, I would hope your databases are behind a firewall.
    Second, with the correct architecture (DMZ, app servers, etc) you can make this data available outside the firewall fairly transparently and third,
    just because it's on the web does not mean the data MUST be available on the internet. This is a good way to make your data available on your
    intranet. If you are worried about people INSIDE your firewall, that still doesn't preclude web based access. Follow Oracle security guidelines.
    Before I show you how to get to your data, let's talk about URLs and URIs. A URL is a Uniform Resource Locater and URI is a Uniform Resource
    Identifier. A URL is the way you would identify a document on the net, i.e. http://www.oracle.com is a URL. A URI is a more generic form of a URL.
    Oracle supports three types of URI: HTTPURIType - basically a URL (which would be like the URL above), XDURIType - a pointer to an XDB resource
    (usually an XML document but can be other objects), and DBURIType - a pointer to database objects.
    It's the DBURIType that we're going to concentrate on here. The DBURIType let's us reference database objects using a file/folder paradigm. The
    format for a DBURI is /oradb/<schema>/<table>. Oradb is shorthand for the database; it is not the database name or SID. My database is named XE
    but I still use oradb in the DBURI. For example, the view we created above is in my XE database, is owned by HR (at least in my case) and is called
    EMPS_AND_DEPTS. This can be referenced as /oradb/HR/EMPS_AND_DEPTS.
    If the view had many rows and you wanted only one of them, you can restrict it by including a predicate. The documentation for XDB has a great
    write up on Using DBURIs.In our case, we are going to write out the entire document. Now that you understand that the DBURI is a pointer to
    objects in our instance, we can use that to access the data as a URL.
    The format for the URL call is http://<machinename>:<port>/<DBURI>
    In my case, my XE database is running on a machine called mach1 and is listening on port 8080. So to see the view we created above, I open my
    browser and navigate to: http//mach1:8080/oradb/HR/EMPS_AND_DEPTS
    The created URL will be as http//mach1:8080/oradb/PUBLIC/EMPS_AND_DEPTS
    If your database is set up correctly and listening on port 8080 (the default), your browser should ask you to login. Login as the user who created the
    view (in my case HR). You should now get an XML document displayed in your browser.
    And that's it. It doesn't get much simpler than that. If you get rid of the descriptive text above, it basically comes down to:
    Create a table or view
    Open your web browser
    Enter a URL
    Enter a user ID and password
    View your XML
    If you notice, Oracle formatted the data as XML for us. Our view returns scalar columns and an XML fragment called Dept. Oracle formatted the
    return results into an XML format.
    And as a side note, if you look closely, you'll see that my URL has PUBLIC where I said to put HR. PUBLIC is a synonym for all objects that your
    logged in user can see. That way, if your user has been granted select access on many schemas, you can use PUBLIC and see any of them.

  • LIKE operator is not working in SQL Query in XML file

    Hi Gurus,
    LIKE operator is not working in SQL query in XML template.
    I am creating a PDF report in ADF using Jdeveloper10g. The XML template is as follows
    <?xml version="1.0" encoding="WINDOWS-1252" ?>
    <dataTemplate name="catalogDataTemplate" description="Magazine
    Catalog" defaultPackage="" Version="1.0">
    <parameters>
    <parameter name="id" dataType="number" />
    <parameter name="ename" dataType="character" />
    </parameters>
    <dataQuery>
    <sqlStatement name="Q1">
    <![CDATA[
       SELECT ename, empno, job, mgr from EMP where deptno=:id and ename LIKE :ename || '%']]>
    </sqlStatement>
    </dataQuery>
    <dataStructure>
    <group name="EmployeeInfo" source="Q1">
    <element name="EmployeeName" value="ename" />
    <element name="EMPNO" value="empno" />
    <element name="JOB" value="job"/>
    <element name="MANAGER" value="mgr" />
    </group>
    </dataStructure>
    </dataTemplate>
    if i pass the parameter value of :ename from UI, it doesn't filter. But if I give ename = :ename it retrieves the data. Can anyone help me why LIKE operator doesn't work here?
    Appreciate your help,
    Shyamal
    email: [email protected]

    Hi
    Well for a start, you are doing some very strange conversions there. For example...
    and to_char(a.msd, 'MM/DD/YYYY') != '11/11/2030'
    and to_char(a.msd, 'MM/DD/YYYY') != '10/10/2030'If a.msd is a date then you should e converting on the other side ie.
    and a.msd != TO_DATE('11/11/2030', 'MM/DD/YYYY')
    and a.msd != TO_DATE('10/10/2030', 'MM/DD/YYYY')Also, you may want to take into consideration nothing being input in :P2_ITEM_NUMBER like this...
    AND INSTR(a.item_number,NVL(:P2_ITEM_NUMBER,a.item_number)) > 0Is item number actually a number or char field? If it's a number, you want to explicitly convert it to a string for using INSTR like this...
    AND INSTR(TO_CHAR(a.item_number),NVL(TO_CHAR(:P2_ITEM_NUMBER),TO_CHAR(a.item_number))) > 0?
    Cheers
    Ben

  • SQL Server 2012 Management Studio: XML XQuery-query the XML Blob using CTE: How to specify the coorelation name in bulk rowset?

    Hi all,
    I just started doing the XML Xquery programming in my SQL Server 2012 Management Studio. I executed the following code:
    --query the XML Blob using a CTE (pulling from the XML file each time) Products
    WITH XmlFile (Contents) AS (
    SELECT CONVERT (XML, BulkColumn)
    FROM OPENROWSET (BULK 'H:\Products.xml', SINGLE_BLOB) ) AS XmlData
    SELECT *
    FROM XmlFile
    GO
    I got the the following Msg:
    Msg 491, Level 16, State 1, Line 4
    A correlation name must be specified for the bulk rowset in the from clause.
    How can I specify the correction name for the bulk rowset in my project?
    Please kindly help, advise and respond.
    Thanks in advance,
    Scott Chang

    Hello Scott,
    You have to assign a table alias for the OPENROWSET =>
    --query the XML Blob using a CTE (pulling from the XML file each time) Products
    WITH XmlFile (Contents) AS (
    SELECT CONVERT (XML, BulkColumn)
    FROM OPENROWSET (BULK 'H:\Products.xml', SINGLE_BLOB) AS MyXML ) AS XmlData
    SELECT *
    FROM XmlFile
    GO
    Olaf Helper
    [ Blog] [ Xing] [ MVP]

  • Multi-level nested tables for repeatable XML Elements

    Hi there,
    Suppose we have a XML Schema „ASchema“ like this (XMLDB schema annotations are left out for simplicity):
    <xs:schema xmlns:xs=" .... " />
    <xs:element name=“A“>
         <xs:complexType>
              <xs:sequence>
                   <xs:element name=“B“ maxOccurs=“unbounded“/>
                        <xs:complexType>
                             <xs:sequence>
                                  <xs:element name = “C“ maxOccurs=“unbounded“/>
                             </xs:sequence>
                        </xs:complexType>
                   </xs:element>
              </xs:sequence>
         </xs:complexType>
    </xs:element>
    </xs:schema>
    After registering this schema in Oracle, I can define a table like this:
    CREATE TABLE ATable
    id NUMBER,
    doc XMLTYPE
    XMLTYPE COLUMN doc
    XMLSCHEMA “ASchema“ ELEMENT “A“
    VARARRAY doc.“XMLDATA“.“B“ STORE AS TABLE “BTable“
    ((PRIMARY KEY (NESTED_TABLE_ID, SYS_NC_ARRAY_INDEX$)) ORGANIZATION INDEX)
    This creates a nested table "BTable" within the table "ATable". So far so good, I can use this nested table to gain faster access on every possible subelement of Element B when I set an appropriate index.
    I now want to create another nested table for element “C“ like this:
    DROP TABLE ATable;
    CREATE TABLE ATable
    id NUMBER,
    doc XMLTYPE
    XMLTYPE COLUMN doc
    XMLSCHEMA “ASchema“ ELEMENT “A“
    VARARRAY doc.“XMLDATA“.“B“ STORE AS TABLE “BTable“
    ((PRIMARY KEY (NESTED_TABLE_ID, SYS_NC_ARRAY_INDEX$)) ORGANIZATION INDEX)
    VARARRAY doc.“XMLDATA“.“B“.“C“ STORE AS TABLE “CTable“
    ((PRIMARY KEY (NESTED_TABLE_ID, SYS_NC_ARRAY_INDEX$)) ORGANIZATION INDEX)
    But this statement fails with the error message something like „ ... no such attribute ... „
    And here's my question: is it possible to create nested tables for repeatable XML Elements that are subelements of other repeatable XML Elements ? And if so, how can I do it ?
    Thank you very much in advance
    Jan

    Found a (partial) solution myself:
    If you add the attribute xdb:storeVarrayAsTable="true" to the root element of the XML schema, Oracle XMLDB generates nested tables for all repeatable XML Elements while registering the XML schema.
    Unfortunately, the names of these nested tables are system-generated, hence it's a bit uncomfortable to set indices on them. You can find out the names of these nested tables as follows:
    select table_name, parent_table_name, parent_table_column from user_nested_tables;
    Further information on that subject is supplied in the following thread:
    Re: default tables for elements with maxoccurs > 1
    It would be nice if there was a way to name the generated nested tables via appropriate XMLDB schema annotations.
    regards
    Jan

  • Issue with Broadcasting a query as xml(excel) in BI 7

    Hi All,
             I have a question.When I try to broadcast my query as xml  using the Filter Navingation tab provided by broadcaster and I select a paritcular characteristic and select multiple values .The receipent gets an email but for each of the values selected , he gets a different report.I need to get just one report for all of the filter selections.
    i.e. For example i select 3 values for a a particular characteristic , when i execute the setting , the report is filtered for each of these values but i get 3 different excel files.I want to get only one for all of these selections.Can it be done?
    Can anybody help? would really appreciate it and assign points.
    Regards
    Abyie

    Please can anybody help? its urgent.
    Thanks
    Abyie

  • Downlod bex query in xml

    Hi all,
    I need to download a bex query in xml format.
    How can do it?
    Best regard
    Gianmarco

    Hi Gianmarco,
    I dont think it is possible with Bex query. However you can have a look at this doc:
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/6765a990-0201-0010-4e97-8aca85883914
    Bye
    Dinesh

  • Combine query and xml recordset

    I'm trying to see what's the best way to combine a query and
    XML recordset.
    Database:
    TableA
    FieldA, FieldB, ...
    Joe, 1
    Bob, 2
    XML from Web Service
    <record id="1" att="Job A" .../>
    <record id="2" att="Job B" .../>
    Need to link TableA.fieldB to matching id attribute from the
    XML recordset.
    Right now, I load theXML recordset along side the query and
    use XPath to search the XML based on parameters from the query that
    I'm looping and output the results to screen.
    <cfloop ...>
    xmlStr = xmlSearch(xmlRecordset,"/root/record[id =
    #qry.fieldB#]");
    <tr><td>qry.fieldA</td><td>xmlStr</td></tr>
    </cfloop>
    Just wondering to see if it's good to do it like this.

    Might be faster to convert the xml to a query and then use
    query of queries with a join statement.

  • SSMS 2012:XML File Query: Importing XML data using a CTE-Incorrect syntax near 'BLOB'?

    Hi all,
    From https://www.simple-talk.com/content/print.aspx?article=1756, I mimicked to create the following sql code to do Importing XML data using a CTE:
    ---Importing XML data using a CTE -----Ad-Hoc XML File Query--simple-talk---1020AM 27 Feb 2015
    ---query the XML Blob using a CTE (pulling from the XML file each time
    USE OPENXMLtesting1
    GO
    With XmlFile (Contents) AS (
    SELECT CONVERT (XML, BulkColumn)
    FROM OPENROWSET (BULK 'C:\XML FilesMicrosoft-Samples\books.xml', SINGLE BLOB) AS XmlData
    SELECT
    FROM XmlFile
    GO
    I got the following message:
    Msg 102, Level 15, State 1, Line 4
    Incorrect syntax near 'BLOB'.
    I have no ideas why it is incorrect in that code statment. Please kindly help, advise and respond.
    Thanks in advance,
    Scott Chang
    P. S. The books.xml file was copied from the Microsoft samples:
    <?xml version="1.0"?>
    <catalog>
    <book id="bk101">
    <author>Gambardella, Matthew</author>
    <title>XML Developer's Guide</title>
    <genre>Computer</genre>
    <price>44.95</price>
    <publish_date>2000-10-01</publish_date>
    <description>An in-depth look at creating applications
    with XML.</description>
    </book>
    <book id="bk102">
    <author>Ralls, Kim</author>
    <title>Midnight Rain</title>
    <genre>Fantasy</genre>
    <price>5.95</price>
    <publish_date>2000-12-16</publish_date>
    <description>A former architect battles corporate zombies,
    an evil sorceress, and her own childhood to become queen
    of the world.</description>
    </book>
    <book id="bk103">
    <author>Corets, Eva</author>
    <title>Maeve Ascendant</title>
    <genre>Fantasy</genre>
    <price>5.95</price>
    <publish_date>2000-11-17</publish_date>
    <description>After the collapse of a nanotechnology
    society in England, the young survivors lay the
    foundation for a new society.</description>
    </book>
    <book id="bk104">
    <author>Corets, Eva</author>
    <title>Oberon's Legacy</title>
    <genre>Fantasy</genre>
    <price>5.95</price>
    <publish_date>2001-03-10</publish_date>
    <description>In post-apocalypse England, the mysterious
    agent known only as Oberon helps to create a new life
    for the inhabitants of London. Sequel to Maeve
    Ascendant.</description>
    </book>
    <book id="bk105">
    <author>Corets, Eva</author>
    <title>The Sundered Grail</title>
    <genre>Fantasy</genre>
    <price>5.95</price>
    <publish_date>2001-09-10</publish_date>
    <description>The two daughters of Maeve, half-sisters,
    battle one another for control of England. Sequel to
    Oberon's Legacy.</description>
    </book>
    <book id="bk106">
    <author>Randall, Cynthia</author>
    <title>Lover Birds</title>
    <genre>Romance</genre>
    <price>4.95</price>
    <publish_date>2000-09-02</publish_date>
    <description>When Carla meets Paul at an ornithology
    conference, tempers fly as feathers get ruffled.</description>
    </book>
    <book id="bk107">
    <author>Thurman, Paula</author>
    <title>Splish Splash</title>
    <genre>Romance</genre>
    <price>4.95</price>
    <publish_date>2000-11-02</publish_date>
    <description>A deep sea diver finds true love twenty
    thousand leagues beneath the sea.</description>
    </book>
    <book id="bk108">
    <author>Knorr, Stefan</author>
    <title>Creepy Crawlies</title>
    <genre>Horror</genre>
    <price>4.95</price>
    <publish_date>2000-12-06</publish_date>
    <description>An anthology of horror stories about roaches,
    centipedes, scorpions and other insects.</description>
    </book>
    <book id="bk109">
    <author>Kress, Peter</author>
    <title>Paradox Lost</title>
    <genre>Science Fiction</genre>
    <price>6.95</price>
    <publish_date>2000-11-02</publish_date>
    <description>After an inadvertant trip through a Heisenberg
    Uncertainty Device, James Salway discovers the problems
    of being quantum.</description>
    </book>
    <book id="bk110">
    <author>O'Brien, Tim</author>
    <title>Microsoft .NET: The Programming Bible</title>
    <genre>Computer</genre>
    <price>36.95</price>
    <publish_date>2000-12-09</publish_date>
    <description>Microsoft's .NET initiative is explored in
    detail in this deep programmer's reference.</description>
    </book>
    <book id="bk111">
    <author>O'Brien, Tim</author>
    <title>MSXML3: A Comprehensive Guide</title>
    <genre>Computer</genre>
    <price>36.95</price>
    <publish_date>2000-12-01</publish_date>
    <description>The Microsoft MSXML3 parser is covered in
    detail, with attention to XML DOM interfaces, XSLT processing,
    SAX and more.</description>
    </book>
    <book id="bk112">
    <author>Galos, Mike</author>
    <title>Visual Studio 7: A Comprehensive Guide</title>
    <genre>Computer</genre>
    <price>49.95</price>
    <publish_date>2001-04-16</publish_date>
    <description>Microsoft Visual Studio 7 is explored in depth,
    looking at how Visual Basic, Visual C++, C#, and ASP+ are
    integrated into a comprehensive development
    environment.</description>
    </book>
    </catalog>

    I found the mistakes I made and I corrected them. The newly revised/corrected code is:
    USE OPENXMLtesting1
    GO
    With XmlFile (Contents) AS (
    SELECT CONVERT (XML, BulkColumn)
    FROM OPENROWSET (BULK 'C:\Temp\books.xml', SINGLE_BLOB) AS XmlData
    SELECT *
    FROM XmlFile
    GO
    It worked: Results
         Contents
    1  <catalog><book.id="bk101"><author>Gambardella.M...
    If I clicked on this, I got a listing of the whole book.xml!!  I don't know what it means.  Please comment and respond.
    Thanks,
    Scott Chang

  • Inst. XDK on Oracle 8.05, just to transform sql-query in xml

    hi,
    id like to install xdk to use xsu to transform a sql query in xml.
    (i didnt find a way to download xsu without xdk)
    i4ve oracle 8.0.5 but i only find 9i-xdk-(pl/sql) - is this correct?
    what do i have to notice when i install
    this package with my orace-ver?
    thanks :o)

    XDK 9.x is not only for Oracle9i Database. You can download the
    9.0.2B XDK for Java and use XSU [or xsu12.jar(xsu11.jar)].

  • Converting Relational query to XML

    set serveroutput on
    This is the code of a query to convert a relational query to xml. This code runs fine when I place the where condition at the end. e.g. where h.hospital_id=1. however when i place no such condition it begins returning errors such as
    set serveroutput on
    set long 10000000
    set linesize 50000
    set lines 20000
    set pagesize 0
    set pages 5
    set feedback off
    set head off
    SET TRIMSPOOL ON
    set long 200000000
    set linesize 32000
    set pagesize 0
    set pages 0
    set feedback off
    set head off
    Select XMLELEMENT("have:HospitalStatus",XMLAttributes('urn:oasis:names:tc:emergency:EDXL:HAVE:1.0 edxl-have_cs01.xsd' AS
                                      "xsi:schemaLocation",
                                              'urn:oasis:names:tc:emergency:EDXL:HAVE:1.0' AS
                                      "xmlns:have",
                                    'http://www.georss.org/georss' AS
                                      "xmlns:n3",
                                    'http://www.opengis.net/gml' AS
                                      "xmlns:gml",
                                    'http://www.w3.org/2001/XMLSchema-instance' AS
                                      "xmlns:xsi",
                                    'urn:oasis:names:tc:ciq:xal:3' AS
                                      "xmlns:xal",
                                    'urn:oasis:names:tc:ciq:xnl:3' AS
                                      "xmlns:xnl",
                                    'urn:oasis:names:tc:ciq:xpil:3' AS
                                      "xmlns:xpil"                                        
         xmlagg(                    
         xmlelement("have:Hospital",
         xmlforest
              (     h.hospital_id,          
                   xmlforest(
                   xmlforest(
                   h.name,               
                   h.info,          
                   h.addresses     ,          
                   h.contact_numbers) as "OrganizationInformation",     
                   xmlforest(
                   h.geo_location) as "OrganizationGeoLocation",
                   h.comments) as "Organization"
                   xmlelement("have:EmergencyDepartmentStatus",
                   (select xmlagg(
                   xmlforest(
                             eds.date_updated,
                   xmlforest(
                             eds.ems_traffic_status,
                             eds.ems_traffic_reason) as "EMSTraffic",          
                   xmlforest(
                             tcl.url,
                             tc.date_updated,
                             tc.code_value,
                             tc.ems_capacity
                        ) as "EMSCapacity",     
                   xmlforest(
                             tcl.url,
                             tc.date_updated,
                             tc.code_value,
                             tc.ems_census) as "EMSCensus",
                             xmlforest(
                             eds.ems_amb_offload_status,
                             eds.ems_amb_offload_min) as "EMSAmbulanceStatus",
                             xmlforest(
                             eds.ems_air_offload_status,
                             eds.ems_air_offload_min )as "EMSAirTransportStatus"
                   from EmergencyDepartmentStatus eds,TriageCode tc,TriageCodeListURN tcl
                   where eds.hospital_id = h.hospital_id and tc.hospital_id = h.hospital_id and tcl.hospital_id = h.hospital_id)),     
                             xmlelement("have:HospitalBedCapacityStatus",
                   (select xmlagg(xmlelement("have:BedCapacity",
                   xmlforest(
                             mb.date_updated,
                             mb.bed_no,
                             mb.bed_type,
                             xmlforest(
                             mb.capacity_status,
                             mb.available_count,
                             mb.baseline_count,
                             mb.additional_24hr,
                             mb.additional_72hr) as "Capacity",
                             mb.comments
                   from MainBeds mb
                   where mb.hospital_id = h.hospital_id and mb.bed_no NOT IN(select mb.bed_no from MainBeds mb, SubBeds sb where mb.bed_no=sb.bed_no )
                   (select xmlagg(xmlelement("have:BedCapacity",
                   xmlforest(
                             mb.date_updated,
                             mb.bed_no ,
                             mb.bed_type,
                             xmlforest(
                             mb.capacity_status
                                                 ) as "Capacity",
                             mb.comments
                                  ),(select xmlagg(
                   xmlforest(
                                  sb.date_updated,
                                  sb.bed_no,
                                  sb.sub_bed_no,
                                  xmlforest(
                                  sb.capacity_status,
                                  sb.available_count,
                                  sb.baseline_count,
                                  sb.additional_24hr,
                                  sb.additional_72hr) as "Capacity",
                                  sb.comments
                                  )from SubBeds sb  where mb.bed_no = sb.bed_no and sb.bed_no=h.hospital_id )
                   from MainBeds mb
                   where mb.hospital_id = h.hospital_id and mb.bed_no in (select unique mb.bed_no from MainBeds md, SubBeds sb where sb.bed_no=mb.bed_no))
                   xmlelement("have:ServiceCoverageStatus",
                   (select xmlagg(
                   xmlforest(
                             scs.date_updated,
                             scs.burn,
                             xmlelement("CardiologySubType",
                                  xmlforest(scs.cardiology_invasive,
                                  scs.cardiology_non_invasssive)) as "CardiologyIndicator",
                             scs.dialysis,
                             scs.emergency_dept,
                             scs.hyperbaric_chamber,
                             scs.infectious_diseases,
                             scs.neonatology,
                             xmlforest(xmlforest(
                                  scs.neurology_invassive,
                                  scs.neurology_non_invasssive) as "NeurologySubType") as "NeurologyIndicator",
                             xmlforest(xmlforest(
                                  scs.obgyn_with_labor,          
                                  scs.obgyn_without_labor) as "OBGYNSubType")as "OBGYNIndicator",
                             scs.opthalmology,
                             scs.orthopedic,
                             scs.pediatrics,
                             xmlforest(
                                  xmlforest(scs.psychiatry_adult_general,
                                  scs.psychiatry_pediatric) as"PsychiatrySubType")as "PsychiatryIndicator",
                             xmlforest(
                                  xmlforest(
                                  sst.date_updated,
                                  sst.general_ward,
                                  sst.adult_general,
                                  sst.pediatrics,
                                  sst.orthopedics,
                                  sst.nuero_surgery,
                                  sst.facial,
                                  sst.cardio_thoracic,
                                  sst.hand,
                                  sst.reimplantation,
                                  sst.spinal,
                                  sst.vascular,
                                  sst.anesthesia) as "SurgerySubTypes") as "SurgeryIndicator",
                             xmlforest(xmlforest(
                             scs.ambulance_services,
                             scs.air_transport_services) as "TransportServicesSubType") as "TransportServicesIndicator",
                             xmlforest(xmlforest(
                             scs.trauma_service,
                             scs.trauma_service_level) as "TraumaCenterServicesSubType")as "TraumaCenterServicesIndicator"
                   from ServiceCoverageStatus scs, SurgerySubTypes sst
                   where scs.hospital_id = h.hospital_id and sst.hospital_id = h.hospital_id)),
                   xmlelement("have:HospitalFacilityStatus",
                   (select xmlagg(     
                   xmlforest(
                             hfs.date_updated,               
                             hfs.hospital_eoc_status,
                             hfs.hospital_eoc_plan,          
                             hfs.clinical_status,
                             xmlforest(
                                  dc.date_updated,
                                  dc.decon_capacity_status,
                                  dc.amb_patients_capacity,
                                  dc.non_amb_patients_capacity) as "DeconCapacity",
                             xmlforest(
                             mc.date_updated,
                             mc.morgue_capacity_status,
                             mc.morgue_capacity_units) as "MorgueCapacity",
                             hfs.facility_status,               
                             hfs.security_status,     
                             xmlforest(
                                  ah.date_update,
                                  ah.admissions,
                                  ah.discharges,
                                  ah.deaths) as "Activity24hr",
                             hfs.comments,
                             hfs.clinical_operations,     
                             hfs.resources_information
                   from HospitalFacilityStatus hfs,Activity24hr ah,MorgueCapacity mc,DeconCapacity dc
                   where hfs.hospital_id = h.hospital_id and ah.hospital_id = h.hospital_id and mc.hospital_id = h.hospital_id
                   and dc.hospital_id = h.hospital_id)),     
                   xmlelement("have:HospitalResourceStatus",
                   (select xmlagg(
                   xmlforest(
                             hr.date_updated,
                             hr.staffing,
                             hr.facility_operations,
                             hr.clinical_operations,     
                             hr.comments
                   from HospitalResourceStatus hr
                   where hr.hospital_id = h.hospital_id)),
              xmlforest(h.last_update_time) as "UpdateTime"
              ))).extract('/*')
    from hospital h;__________________________________________________________________________________________________________
    ERROR:
    ORA-31011: XML parsing failed
    ORA-19202: Error occurred in XML processing
    LPX-00225: end-element tag "HOSPITAL_EOC_STATUS" does not match start-element tag "have:HospitalStatus"
    Error at line 1
    ORA-06512: at "SYS.XMLTYPE", line 111
    Edited by: 872489 on 14-Jul-2011 03:59
    Edited by: 872489 on Jul 14, 2011 9:11 AM
    Apologies for lack of formatting earlier

    Please repost this and use the tag with some decent formatting.
    See the FAQ Posting Guidelines on the main page of this XMLDB OTN Forum                                                                                                                                                                                                                                                                                               

  • Hierachy Query problem

    Hi all,
    I have some problem of retrieving sql from two table using Hierachy Query.
    Below is two table and excepted table and my query.
    I cannot be think how to join and query to get result_table
    Please kindly repair and guid me. Thank.
    table_1
    DATA_DT_ID MKT_TYPE_IND      DATA_DT    CONS_WGT   INDEX_ID INDEX_CODE CONS_CODE
    20060331     1     31/03/2006     1     -1002     IDX_1B          -1
    20060331     2     31/03/2006     1     -1002     IDX_1B          -1
    20060331     1     31/03/2006     0.7     -1001     IDX_1A          -2
    20060331     2     31/03/2006     0.7     -1001     IDX_1A          -2
    20060331     1     31/03/2006     0.3     -1001     IDX_1A          -1
    20060331     2     31/03/2006     0.3     -1001     IDX_1A          -1
    20060401     1     01/04/2006     1     -1003     IDX_1C          -2
    20060402     1     02/04/2006     1     -1003     IDX_1C          -2
    20060401     2     01/04/2006     1     -1003     IDX_1C          -2
    20060402     2     02/04/2006     1     -1003     IDX_1C          -2
    20060401     1     01/04/2006     1     -1002     IDX_1B          -1
    20060402     1     02/04/2006     1     -1002     IDX_1B          -1
    20060401     2     01/04/2006     1     -1002     IDX_1B          -1
    20060402     2     02/04/2006     1     -1002     IDX_1B          -1
    20060401     1     01/04/2006     0.7     -1001     IDX_1A          -2
    20060402     1     02/04/2006     0.7     -1001     IDX_1A          -2
    20060401     2     01/04/2006     0.7     -1001     IDX_1A          -2
    20060402     2     02/04/2006     0.7     -1001     IDX_1A          -2
    20060401     1     01/04/2006     0.3     -1001     IDX_1A          -1
    20060402     1     02/04/2006     0.3     -1001     IDX_1A          -1
    20060401     2     01/04/2006     0.3     -1001     IDX_1A          -1
    20060402     2     02/04/2006     0.3     -1001     IDX_1A          -1
    table_2
    DATA_DT  CHILD_INDEX_WGT MKT_TYPE_IND INDEX_ID CHILD_INDEX_ID INDEX_CODE CHILD_INDEX_CODE
    31/03/2006     0.3          2      -3001          -1001      IDX_3A          IDX_1A
    31/03/2006     0.7          2      -3001          -1002      IDX_3A          IDX_1B
    31/03/2006     0.2          2      -3002          -1001      IDX_3B          IDX_1A
    31/03/2006     0.8          2      -3002          -1003      IDX_3B          IDX_1C
    31/03/2006     0.5          2      -3003          -3001      IDX_3C          IDX_3A
    01/04/2006     0.3          2      -3001          -1001      IDX_3A          IDX_1A
    01/04/2006     0.7          2      -3001          -1002      IDX_3A          IDX_1B
    01/04/2006     0.2          2      -3002          -1001      IDX_3B          IDX_1A
    01/04/2006     0.8          2      -3002          -1003      IDX_3B          IDX_1C
    01/04/2006     0.5          2      -3003          -3001      IDX_3C          IDX_3A
    01/04/2006     0.5          2      -3003          -3002      IDX_3C          IDX_3B
    Result_table
    DATA_DT    INDEX_CODE CHILD_INDEX_CODE CONS_CODE MKT_TYPE_IND BLENDED_WGT
    31/03/2006  IDX_3C     IDX_1B          -1        2          5*.7*1
    31/03/2006  IDX_3A     IDX_1B          -1        2          7*1
    31/03/2006  IDX_3C     IDX_1A          -2        2          5*.3*.7
    31/03/2006  IDX_3A     IDX_1A          -2        2          3*.7
    31/03/2006  IDX_3C     IDX_1A          -1        2          5*.3*.3
    31/03/2006  IDX_3A     IDX_1A          -1        2          3*.3
    01/04/2006  IDX_3C     IDX_1C          -2        2          5*.8*1
    01/04/2006  IDX_3B     IDX_1C          -2        2          8*1
    01/04/2006  IDX_3C     IDX_1B          -1        2          5*.7*1
    01/04/2006  IDX_3A     IDX_1B          -1        2          7*1
    01/04/2006  IDX_3C     IDX_1A          -2        2          5*.2*.7
    01/04/2006  IDX_3C     IDX_1A          -2        2          5*.3*.7
    01/04/2006  IDX_3B     IDX_1A          -2        2          2*.7
    01/04/2006  IDX_3A     IDX_1A          -2        2          3*.7
    01/04/2006  IDX_3C     IDX_1A          -1        2          5*.2*.3
    01/04/2006  IDX_3C     IDX_1A          -1        2          5*.3*.3
    01/04/2006  IDX_3B     IDX_1A          -1        2          2*.3
    01/04/2006  IDX_3A     IDX_1A          -1        2          3*.3with m_que as
    select distinct wei.data_dt,wei.index_code, wei.child_index_code, con.index_code child_child_index,
    wei.child_index_wgt, con.cons_wgt child_child_wgt,con.cons_code, con.mkt_type_ind
    from table_1 wei
    join table_2 con on wei.data_dt = con.data_dt
    where con.index_code < wei.child_index_code
    i_que as
    select data_dt, index_code, child_index_code, cons_code, mkt_type_ind,
    substr(SYS_CONNECT_BY_PATH(gs_child_index_wgt, '*'),3) BLENDED_WGT
    from (m_que)
    start with index_code = 'IDX_3C'
    connect by prior child_index_code = index_code
    select data_dt,index_code,child_index_code,cons_code,mkt_type_ind,BLENDED_WGT from i_que;

    Hi,
    Thank for your suggestion, but it is not work, when i put my query the result is nothing display.
    Another problem is i_que portion
    SYS_CONNECT_BY_PATH() can only retrieve BLENDED_WGT level is only 2nd level. Actual Result_table of BLENDED_WGT display 3rd level.
    I doubt is because of main select portion or all my query is wrong.
    Thanks

  • Re: (forte-users) Hi - Query on XML Import document -Hang

    Double check that your XML is valid. I've seen
    importDocument hang when I'm missing an end tag.
    I don't think it's a validating parser.
    Of course, there's no documentation, so.... :)
    Chris
    --- "Saravanan, Lakshmi N." <lnarayanoxhp.com> wrote:
    Hi guys,
    I am trying to import an XML document from a
    Memory stream object. I
    got the example
    from this group ( It was very helpful ).
    Sample Code :
    l_MemStr : MemoryStream = new;
    l_MemStr.Open( SP_AM_READ_WRITE );
    l_MemStr.WriteText( source = l_XMLData );
    l_MemStr.Seek( position=0 );
    -- Create a Document object from the memory stream
    myDoc : Document = new;
    myDoc.importdocument( l_MemStr );
    After this line nothing seems to happen.. the
    partition just hangs... keeps
    the CPU busy.
    If i deploy the same in a NT or on a IBM box it
    works fine. The problem is
    with the Sequent box..( i guess ).
    Did any of you guys face a problem like this...
    Please let us know..
    I would really appreciate it.
    Thanks
    Laks
    For the archives, go to:
    http://lists.xpedior.com/forte-users and use
    the login: forte and the password: archive. To
    unsubscribe, send in a new
    email the word: 'Unsubscribe' to:
    forte-users-requestlists.xpedior.com
    http://mail.yahoo.com/

    Well, Forte have agreed to release a patch for the XML bug on DG Unix with
    Forte Version 3.0.M.2. I've attached a related mail with this.
    - Charu.
    -----Original Message-----
    From: Epari, Madhusudhan [mailto:meparioxhp.com]
    Sent: Friday, September 01, 2000 7:59 AM
    To: 'Amin, Kamran'
    Cc: 'forte-userslists.xpedior.com'
    Subject: RE: (forte-users) Hi - Query on XML Import document - Hang
    I did check the xml by opening it in IE 5.0 for it's well-formedness. Still
    it's failing on sequent box.
    -----Original Message-----
    From: Amin, Kamran [mailto:kamran.aminlendware.com]
    Sent: Friday, September 01, 2000 10:55 AM
    To: 'Epari, Madhusudhan'
    Subject: RE: (forte-users) Hi - Query on XML Import document - Hang
    Well not really. One way to check if the xml is valid is to open it in IE
    5.0. If its well formed then it will show up otherwise it will give you an
    error. Also the document object is not the best code that came out of Forte
    and has errors, so this might be a bug you will have to report. And they
    are not giving any new patches until 3.5 comes out in 2 months.
    ka
    -----Original Message-----
    From: Epari, Madhusudhan [mailto:meparioxhp.com]
    Sent: Friday, September 01, 2000 10:52 AM
    To: 'Christopher Fury'
    Cc: 'forte-userslists.xpedior.com'
    Subject: RE: (forte-users) Hi - Query on XML Import document - Hang
    If the XML is invalid it should fail on all boxes. This should be a sequent
    specific problem.
    Madhu
    -----Original Message-----
    From: Christopher Fury [mailto:cfuryyahoo.com]
    Sent: Friday, September 01, 2000 9:37 AM
    To: 'forte-userslists.xpedior.com'
    Subject: Re: (forte-users) Hi - Query on XML Import document - Hang
    Double check that your XML is valid. I've seen
    importDocument hang when I'm missing an end tag.
    I don't think it's a validating parser.
    Of course, there's no documentation, so.... :)
    Chris
    --- "Saravanan, Lakshmi N." <lnarayanoxhp.com> wrote:
    Hi guys,
    I am trying to import an XML document from a
    Memory stream object. I
    got the example
    from this group ( It was very helpful ).
    Sample Code :
    l_MemStr : MemoryStream = new;
    l_MemStr.Open( SP_AM_READ_WRITE );
    l_MemStr.WriteText( source = l_XMLData );
    l_MemStr.Seek( position=0 );
    -- Create a Document object from the memory stream
    myDoc : Document = new;
    myDoc.importdocument( l_MemStr );
    After this line nothing seems to happen.. the
    partition just hangs... keeps
    the CPU busy.
    If i deploy the same in a NT or on a IBM box it
    works fine. The problem is
    with the Sequent box..( i guess ).
    Did any of you guys face a problem like this...
    Please let us know..
    I would really appreciate it.
    Thanks
    Laks
    For the archives, go to:
    http://lists.xpedior.com/forte-users and use
    the login: forte and the password: archive. To
    unsubscribe, send in a new
    email the word: 'Unsubscribe' to:
    forte-users-requestlists.xpedior.com
    http://mail.yahoo.com/
    For the archives, go to: http://lists.xpedior.com/forte-users and use
    the login: forte and the password: archive. To unsubscribe, send in a new
    email the word: 'Unsubscribe' to: forte-users-requestlists.xpedior.com
    For the archives, go to: http://lists.xpedior.com/forte-users and use
    the login: forte and the password: archive. To unsubscribe, send in a new
    email the word: 'Unsubscribe' to: forte-users-requestlists.xpedior.com
    For the archives, go to: http://lists.xpedior.com/forte-users and use
    the login: forte and the password: archive. To unsubscribe, send in a new
    email the word: 'Unsubscribe' to: forte-users-requestlists.xpedior.com

  • Sql query, from xml to nested table

    Hello!
    I have DB table: my_table
    It has 2 fields: file_id and file_data (it's clob with xml)
    I need to write query that returns info from xml using nested table (Oracle v.9)
    The number of rows witch will return query must be equal to number of files (file_id)
    Structure of XML:
    <?xml version = "1.0" encoding = "utf-8"?>
    <head>
    <AAA v1="a" v2="b">
    <BBB p1="1" p2="2"/>
    <BBB p1="3" p2="4"/>
    </AAA>
    <AAA v1="c" v2="d">
    <BBB p1="5" p2="6"/>
    <BBB p1="7" p2="8"/>
    <BBB p1="9" p2="0"/>
    </AAA>
    </head>
    I have query, witch works! but not optimally! each CLOB scaned 3 times - I want to scan it once!
    SELECT an.file_id,
    CAST(MULTISET(SELECT extract(VALUE(val2),'//@v1').getStringVal() v1,
    extract(VALUE(val2),'//@v2').getStringVal() v2,
    CAST(MULTISET(SELECT extract(VALUE(val3),'//@p1').getStringVal() p1,
    extract(VALUE(val3),'//@p2').getStringVal() p2,
    FROM TABLE (XMLSEQUENCE(XMLTYPE(an.file_data).EXTRACT('/head/AAA/BBB[../@v1='||extract(VALUE(val2),'//@v1').getStringVal()||']'))) val3) AS T_VAL3) info
    FROM TABLE (XMLSEQUENCE(XMLTYPE(an.file_data).EXTRACT('/head/AAA'))) val2) AS T_VAL2) head
    FROM (SELECT olr.*
    FROM my_table olr,
    TABLE (XMLSEQUENCE(XMLTYPE(file_data)).EXTRACT('/head'))) val1) an
    PLEASE, help me to rewrite this query!

    I assume you're using nested objects like these to hold the result?
    create type t_val3_rec as object ( p1 number, p2 number );
    create type t_val3 as table of t_val3_rec;
    create type t_val2_rec as object ( v1 varchar2(30), v2 varchar2(30), c1 t_val3 );
    create type t_val2 as table of t_val2_rec;
    /then this query should work :
    SELECT t.file_id
         , CAST(
             MULTISET(
               SELECT extractvalue(value(x1), '/AAA/@v1')
                    , extractvalue(value(x1), '/AAA/@v2')
                    , CAST(
                        MULTISET(
                          SELECT extractvalue(value(x2), '/BBB/@p1')
                               , extractvalue(value(x2), '/BBB/@p2')
                          FROM TABLE(XMLSequence(extract(value(x1), '/AAA/BBB'))) x2
                        AS t_val3
               FROM TABLE(XMLSequence(extract(value(x), '/head/AAA'))) x1
             AS t_val2
    FROM my_table t
       , TABLE(XMLSequence(extract(xmltype(t.file_data), '/head'))) x
    ;

Maybe you are looking for