SELECT from XML to get multiple rows

We are trying to set up web services to facilitate access to a central asset database. I’m able to make the request, & I store the response in the following table:
CREATE TABLE assets
(asset_name VARCHAR2(40),
asset_xml XMLType,
add_dt DATE);
Different asset types can have the same name so when I get a response there may be several assets returned with the same name but different types as seen in this formatted XML:
<soapenv:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<AssetDetailsResponse>
<Asset>
<ID>44535</ID>
<AssetName>asset1</AssetName>
<TypeName>Server</TypeName>
<Status>Active</Status>
<SerialNumber>jk823</SerialNumber>
<Business>Finance</Business>
<Vendor>hewlett packard</Vendor>
<Location>
<CountryName>United States</CountryName>
<StateProvName>Ohio</StateProvName>
<CityTownName>Cincinnati</CityTownName>
<Street>2875 Vine Street</Street>
<PostalCode>45229</PostalCode>
</Location>
</Asset>
<Asset>
<ID>453051</ID>
<AssetName>asset1</AssetName>
<TypeName>Tape Backup</TypeName>
<Status>Inactive</Status>
<SerialNumber>s97032</SerialNumber>
<Business>Sales</Business>
<Vendor>Any vendor</Vendor>
<Location>
<CountryName>United States</CountryName>
<StateProvName>Ohio</StateProvName>
<Street>7683 Main Street</Street>
<CityTownName>Cincinnati</CityTownName>
<PostalCode>45492</PostalCode>
</Location>
</Asset>
</AssetDetailsResponse>
</soapenv:Body>
</soapenv:Envelope>
The following query works but the assets are strung together rather than on separate rows:
SQL> SELECT extract(asset_xml, '//AssetName/text()') from gewscadb;
EXTRACT(ASSET_XML,'//ASSETNAME/TEXT()')
asset1asset1
I have tried the following queries to return separate rows but they return “no rows selected”:
SELECT a.asset_id, a.asset_name
FROM assets,
XMLTABLE('/Asset' PASSING assets.asset_xml
COLUMNS asset_id VARCHAR2(20) PATH '/Asset/ID',
asset_name VARCHAR2(30) PATH '/Asset/AssetName') a;
SELECT a.asset_id, a.asset_name
FROM assets,
XMLTABLE('/AssetDetailsResponse'
PASSING assets.asset_xml
COLUMNS asset_id VARCHAR2(20) PATH '/AssetDetailsResponse/Asset/ID',
asset_name VARCHAR2(30) PATH '/AssetDetailsResponse/Asset/AssetName') a;
I suspect there is a problem with my path names in these queries. Can someone please provide some guidance on how I can get a separate row for each asset?

Hi,
You must use a double slash to extract assets nodes :
WITH assets AS (
SELECT xmltype('<soapenv:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
<AssetDetailsResponse>
<Asset>
<ID>44535</ID>
<AssetName>asset1</AssetName>
<TypeName>Server</TypeName>
<Status>Active</Status>
<SerialNumber>jk823</SerialNumber>
<Business>Finance</Business>
<Vendor>hewlett packard</Vendor>
<Location>
<CountryName>United States</CountryName>
<StateProvName>Ohio</StateProvName>
<CityTownName>Cincinnati</CityTownName>
<Street>2875 Vine Street</Street>
<PostalCode>45229</PostalCode>
</Location>
</Asset>
<Asset>
<ID>453051</ID>
<AssetName>asset1</AssetName>
<TypeName>Tape Backup</TypeName>
<Status>Inactive</Status>
<SerialNumber>s97032</SerialNumber>
<Business>Sales</Business>
<Vendor>Any vendor</Vendor>
<Location>
<CountryName>United States</CountryName>
<StateProvName>Ohio</StateProvName>
<Street>7683 Main Street</Street>
<CityTownName>Cincinnati</CityTownName>
<PostalCode>45492</PostalCode>
</Location>
</Asset>
</AssetDetailsResponse>
</soapenv:Body>
</soapenv:Envelope>') asset_xml
FROM dual
SELECT a.asset_id, a.asset_name
FROM assets,
XMLTABLE(
'//Asset' -- << Here
PASSING assets.asset_xml
COLUMNS asset_id VARCHAR2(20) PATH '/Asset/ID',
         asset_name VARCHAR2(30) PATH '/Asset/AssetName'
) a;

Similar Messages

  • How to get multiple rows from database table?

    hello !
    I need to get multiple rows from a OLEDB database table and display them on a table object.
    I did "Wrap in subfrom" on the table,  set  subform of the table to "flowed", and checked "Repeat row for each data item" of Row1 of the table.
    But I can get only one row on the table object.
    I need your help.
    Thanks

    Hi,
    best practices when deleting multiple rows is to do this on the business service, not the view layer for performance reasons. When you selected the rows to delete and press submit, then in a managed bean you access thetable instance (put a reference to a managed bean from the table "binding" property") and call getSeletedRowKeys. In JDeveloper 11g, ADF Faces returns the RowKeySet as a Set of List, where each list conatins the server side row key (e.g. oracle.jbo.Key) if you use ADF BC. Then you create a List (ArrayList) with this keys in it and call a method exposed on the business service (through a method activity in ADF) and pass the list as an argument. On the server side you then access the View Object that holds the data and find the row to delte by the keys in the list
    Example 134 here: http://blogs.oracle.com/smuenchadf/examples/#134 provides you with the code
    Frank

  • Loading xml file with multiple rows

    I am loading data from xml files using xsl for transformation. I have created xsl's and loaded some of the data. In an xml file with multiple row, it's only loading one (the first) row. Any idea how I can get it to read and load all the records in the file???

    Could some please help me with the above. I desparately need to move forward.

  • Get multiple rows from mysql query in NetBeans

    Hi, I am working on a project in NetBeans 6.I have a checkboxlist, and I have a variable in which I save the selected values of the checkboxlist.Now, I want to make a query that will get the rows of the rowset that have the same id as the selected values.for example, I have a checkboxlist that has the following values: Helen, Maria, Anna.The user checks the first two, so I have a variable String[] "checked" that has in it the data 1,2.Now, I have a rowset that has the following query:
    SELECT ALL person.age
    FROM person
    WHERE person.id=? or something like this.I want the parameters to have the values (1,2) so that the rowset has the results of the ages of the two first rows.How do I accomplish that?I am assuming that with one "?" it can't be done because I need multiple parameters. Will something like this work: WHERE person.id IN something,but what will something be?

    christomar wrote:
    I have a rowset that has the following query:
    SELECT ALL person.age
    FROM person
    WHERE person.id=? or something like this.I want the parameters to have the values (1,2) so that the rowset has the results of the ages of the two first rows.How do I accomplish that?Use a PreparedStatement. You probably first need to read the Sun JDBC Tutorial before you do anything.
    I am assuming that with one "?" it can't be done because I need multiple parameters. I've seen people use up to 76 parameters so yes it can be done, it will look like this:
    Will something like this work: WHERE person.id IN something,Yes, you can submit any SQL you want as long as your db supports it (all support ANSI i believe)
    but what will something be?something in that context would be a list/set of data, but you're getting ahead of yourself I think. do the tutorial and look at some code

  • Issue in retrieving all the records from ADF Table with multiple row

    Hi,
    As per my requirement, I need to fill the table with multi selected LOV values and when user clicks on commit, I need to save them to database.
    I am using ADF 11g, Multi select table. Using the below ADD method, I am able to add the records but if user clicks on cancel, I need to remove those from view and clear the table as well.
    But the Issue I am facing is, in my cancel method, always I am getting half of the records. Lets assume table contains 100 records but in my cancel method, I am getting only 50 records.
    Please let me know what is the issue in my source code.
    ADD Method:
    public void insertRecInCMProcessParamVal(String commType, String processType, Number seqNumber){       
    try{
    Row row = this.getCmProcessParamValueView1().createRow();
    row.setAttribute("ParamValue7", commType);
    row.setAttribute("ProcessType", processType);
    row.setAttribute("CreationDate", new Date());
    row.setAttribute("CreatedBy", uid);
    row.setAttribute("ParamValueSeqNum", seqNumber);
    row.setAttribute("ProcessedFlag", "N");
    this.getCmProcessParamValueView1().insertRow(row);
    }catch(Exception e){           
    e.printStackTrace();
    Table Code:
    <af:table value="#{bindings.CmProcessParamValueView11.collectionModel}"
    var="row"
    rows="#{bindings.CmProcessParamValueView11.rangeSize}"
    emptyText="#{bindings.CmProcessParamValueView11.viewable ? 'No data to display.' : 'Access Denied.'}"
    fetchSize="#{bindings.CmProcessParamValueView11.rangeSize}"
    rowBandingInterval="1"
    selectedRowKeys="#{bindings.CmProcessParamValueView11.collectionModel.selectedRow}"
    selectionListener="#{bindings.CmProcessParamValueView11.collectionModel.makeCurrent}"
    rowSelection="multiple"
    binding="#{backingBeanScope.backing_app_RunCalcPage.t1}"
    id="t1" width="100%" inlineStyle="height:100px;" >
    <af:column sortProperty="ParamValue6"
    sortable="true"
    headerText="#{bindings.CmProcessParamValueView11.hints.ParamValue6.label}"
    id="c1" visible="false">
    <af:inputText value="#{row.bindings.ParamValue6.inputValue}"
    label="#{bindings.CmProcessParamValueView11.hints.ParamValue6.label}"
    required="#{bindings.CmProcessParamValueView11.hints.ParamValue6.mandatory}"
    columns="#{bindings.CmProcessParamValueView11.hints.ParamValue6.displayWidth}"
    maximumLength="#{bindings.CmProcessParamValueView11.hints.ParamValue6.precision}"
    shortDesc="#{bindings.CmProcessParamValueView11.hints.ParamValue6.tooltip}"
    id="it3">
    <f:validator binding="#{row.bindings.ParamValue6.validator}"/>
    </af:inputText>
    </af:column>
    <af:column sortProperty="ParamValue7"
    sortable="true"
    headerText="Comm Type"
    id="c2">
    <af:inputText value="#{row.bindings.ParamValue7.inputValue}"
    label="#{bindings.CmProcessParamValueView11.hints.ParamValue7.label}"
    required="#{bindings.CmProcessParamValueView11.hints.ParamValue7.mandatory}"
    columns="#{bindings.CmProcessParamValueView11.hints.ParamValue7.displayWidth}"
    maximumLength="#{bindings.CmProcessParamValueView11.hints.ParamValue7.precision}"
    shortDesc="#{bindings.CmProcessParamValueView11.hints.ParamValue7.tooltip}"
    id="it4">
    <f:validator binding="#{row.bindings.ParamValue7.validator}"/>
    </af:inputText>
    </af:column>
    <af:column sortProperty="ParamValue8"
    sortable="true"
    headerText="#{bindings.CmProcessParamValueView11.hints.ParamValue8.label}"
    id="c3" visible="false">
    <af:inputText value="#{row.bindings.ParamValue8.inputValue}"
    label="#{bindings.CmProcessParamValueView11.hints.ParamValue8.label}"
    required="#{bindings.CmProcessParamValueView11.hints.ParamValue8.mandatory}"
    columns="#{bindings.CmProcessParamValueView11.hints.ParamValue8.displayWidth}"
    maximumLength="#{bindings.CmProcessParamValueView11.hints.ParamValue8.precision}"
    shortDesc="#{bindings.CmProcessParamValueView11.hints.ParamValue8.tooltip}"
    id="it2">
    <f:validator binding="#{row.bindings.ParamValue8.validator}"/>
    </af:inputText>
    </af:column>
    </af:table>
    Backing Bean Code:
    DCBindingContainer dcBindings=(DCBindingContainer)getBindings();
    DCIteratorBinding dcIterator=dcBindings.findIteratorBinding("CmProcessParamValueView1Iterator");
    RowSetIterator rs = dcIterator.getRowSetIterator();
    System.out.println("In Cancel Row Count is : "+ rs.getRowCount());
    if (rs.getRowCount() > 0) {
    Row row = rs.first();
    row.refresh(Row.REFRESH_UNDO_CHANGES);
    row.remove();
    while (rs.hasNext()) {
    int count = rs.getRowCount();
    System.out.println("Count is : "+ count);
    Row row = rs.next();
    System.out.println("Row === "+ row);
    if(row != null){                   
    row.refresh(Row.REFRESH_UNDO_CHANGES);
    row.remove();
    Thanks.

    Issue resolved.
    remove selectionListener and selectedRowKeys....
    code to get all the selectedRows.
    RowSetIterator rs = dcIterator.getRowSetIterator();
    RowKeySet rks = this.t1.getSelectedRowKeys();
    Iterator rksIter = rks.iterator();
    while (rksIter.hasNext()) {
    List l = (List) rksIter.next();
    Key key = (Key)l.get(0);
    Row row = rs.getRow(key);
    Thanks.

  • How to get multiple rows at one time in a table?

    hi
    I have a JTable bound with ViewObject and i use multiple selection mode setting to get selection row.
    My question is when i select more then one row at one time i only can get those index from JTable but can't get those rows from ViewObject.is it possible to get rows from ViewObject? or how to use JTable row index to get row from ViewObject?

    repost

  • How to update xml attributes as multiple rows

    I am new to this technology, but i need to show the result
    in xml document i have to update these attributes get from Databse utility class.
    <equipment object="" manufacturer="" part_number="" type="" model="" items="" accessories="">
    <equipment object="" manufacturer="" part_number="" type="" model="" items="" accessories="">By using XSLT Doucment i have to show this in table format multiple rows of data.
    I'll be happy if anyone tell me the example.

    Now the changed data must be exported back into the XML file, meaning that the content of certain elements must be updated. How can this be done with XSLT?
    XSLT approach:  check these online tutorial
    http://www.xml.com/pub/a/2000/08/02/xslt/index.html
    http://www.xml.com/pub/a/2000/06/07/transforming/index.html
    ABAP approach:
    for example you have the xml (original) in a string called say xml_out .
    data: l_xml  type ref to cl_xml_document ,
            node type ref to if_ixml_node  .
    create object l_xml.
    call method l_xml->parse_string
      exporting
        stream = xml_out.
    node = l_xml->find_node(
        name   = 'IDENTITY'
       ROOT   = ROOT
    l_xml->set_attribute(
        name    = 'Name'
        value   = 'Charles'
        node    = node
    (the above example reads the element IDENTITY and sets attribute name/value to the same)
    like wise you can add new elements starting from IDENTITY using various methods available in class CL_XML_DOCUMENT
    so how do I access the XML file in order to update it?
    you have already read this XML into a ABAP variable right?
    Sorry couldnt understand your whole process, why do you need to read local XML file?
    Raja

  • Get Multiple Rows into internal Table using Webdynpro Alv Display ..

    Hi guys ,
    I need to find out the logic for getting all the selected rows into the internal table.
    When i display the ALV Output on webdypro screen .
    USer Selects multiple rows for further processing ..
    Ineed to get all the rows selected by user into an internal table .
    Please let me know how to achive this ...
    Thanks in advance for quick reply
    Regards
    Saurabh Goel

    Hi,
    You need to use the method GET_SELECTED of IF_WD_CONTEXT_NODE to get the rows selected. Also ccheck for the paramters of that method, this retruns the element set.
    This meets your requirement.
    Regards,
    Lekha.

  • How to extract a clob xml string with multiple row of table tag. in 10g

    i have a xml value like:
    <table><c1>0</c1><c2>Mr</c2><c3>abc</c3><c4>Sharma</c4></table>
    <table><c1>0</c1><c2>Mrs</c2><c3>abcd</c3><c4>Sharma</c4></table>
    <table><c1>0</c1><c2>Mr</c2><c3>sabc</c3><c4>Sharma</c4></table>
    <table><c1>0</c1><c2>Mrs</c2><c3>sdabc</c3><c4>Sharma</c4></table>
    <table><c1>0</c1><c2>Mr</c2><c3>dabc</c3><c4>Sharma</c4></table>
    <table><c1>0</c1><c2>Mr</c2><c3>adbc</c3><c4>Sharma</c4></table>
    i want to insert each of <c> value in a table with respective columns according c1,c2,c3,c4
    pls suggest me what to do
    I use extract(xml, '/table) tab but it just read first one line & return error for other

    Can you plz explain to me thisIt is because you did not provide us with a valid xml structure so I used 11g's xmlparse function to create a xmltype even with the xml not being valid (no root tag).
    With a valid xml structure I could use the xmltype constructor instead and go on the same way as before:
    SQL> select *
      from xmltable (
             'table'
             passing xmltype ('
                            <root>
                            <table><c1>0</c1><c2>Mr</c2><c3>abc</c3><c4>Sharma</c4></table>
                            <table><c1>0</c1><c2>Mrs</c2><c3>abcd</c3><c4>Sharma</c4></table>
                            <table><c1>0</c1><c2>Mr</c2><c3>sabc</c3><c4>Sharma</c4></table>
                            <table><c1>0</c1><c2>Mrs</c2><c3>sdabc</c3><c4>Sharma</c4></table>
                            <table><c1>0</c1><c2>Mr</c2><c3>dabc</c3><c4>Sharma</c4></table>
                            <table><c1>0</c1><c2>Mr</c2><c3>adbc</c3><c4>Sharma</c4></table>
                            </root>').extract ('root/table')
             columns c1 number path 'c1', c2 varchar2 (4) path 'c2', c3 varchar2 (6) path 'c3', c4 varchar2 (6) path 'c4')
            C1 C2     C3        C4      
             0 Mr     abc       Sharma  
             0 Mrs    abcd      Sharma  
             0 Mr     sabc      Sharma  
             0 Mrs    sdabc     Sharma  
             0 Mr     dabc      Sharma  
             0 Mr     adbc      Sharma  
    6 rows selected.

  • JSF datatable to get multiple row values

    I want to get values of SelectBooleanCheckbox and SelectOneMenu in jsf bean from datatable for multiple rows?

    You can find an example here: http://balusc.blogspot.com/2006/06/using-datatables.html

  • How to get multiple Rows in UCCX DB

    Hi All,
    Here is the scenario. One of customer has DB which return the multiple rows of data by querying against one Field.
    suppose there is a Field "National ID Number"  which fetches cutomers' more than one account like post paid customer , prepaid customer, corporate customer etc in different Rows then how could i check this if the customer has more than one Account system should ask about the particular Account Number.
    any help would be grateful for me.
    Thanks

    Is the following way seem correct to store values in an array var
    db read
      successful
        label get_next_record
        db get
          successful
            /* Action to store values in Array variable */
                        Array[c]=accno
    /* “accno” is a variable with Big Dec Type having all possible values fetched by multiple rows */
                        c=c+1 /* where “c” is an index var */
                        goto get_next_record
          no data
            goto no_more_records
    label no_more_records

  • Getting multiple row value on valuechange of selectBooleanCheckbox in table

    Hello All,
    I am using jDeveloper 11.1.1.5. I have a java class which is returning me a list. I have created a data control of my class and I am using it on my page as a table.
    On my page I have inserted a text box selectedamount. In my table there are 4 columns Type, Qty, Amount and one boolean value select. I have changed column select to selectBooleanCheckbox. and I have specified its value as true(when selected) and false(when deselected). Which is getting reflected in my pagedef file.
    There are 4 rows coming in table and displaying properly.
    Now my requirement is on value change of selectBooleanCheckbox if user selects the rows I want to add the Amount for the selected row and I have to set it to the text box selectedamount.
    On value change of selectBooleanCheckbox I have written a method. Code snippet is like this:
    +public void valueChanged(ValueChangeEvent valuechangeevent) {+
    +if (valuechangeevent.getNewValue() == valuechangeevent.getOldValue()) {+
    System.out.println("new value is same as old value");
    +} else {+
    System.out.println("************************new value is other than old value**********************************");
    DCBindingContainer bindings =(DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
    DCIteratorBinding iter = bindings.findIteratorBinding("NAME OF MY ITERATOR");
    float temp2 = 0;
    Row currentRow ;
    int count = (int)iter.getViewObject().getEstimatedRowCount();
    for (int i=1; i<=count;i++) {
    currentRow =   iter.getRowAtRangeIndex(i);
    +if(currentRow != null) {+
    if(true == currentRow.getAttribute("select"))
    +{+
    temp2= temp2 + Float.parseFloat(currentRow.getAttribute("totAmount").toString());
    System.out.println("value of total amount after adding is :: "+ temp2);
    +}+
    +}+
    +}+
    After this I am setting temp2 to selectedamount textbox.
    But I am not getting the desired value in the textbox.
    Is there any other method I can achieve this.
    Thanks
    Navin K

    Inside f(currentRow != null) When I added
    System.out.println(currentRow.getAttribute("select"));
    It is showing as null.
    So select attribute is not getting assigned as true or false while checking and unchecking selectboolean checkbox.
    Am I missing something ?

  • How to get multiple row values in one text box while clicking one row from grid?

    hi friends,
               i am working on flex4 web application i am using  one datagrid ,it have two records(bills),one button and one text box.
    ex:
    customername      salesrepname   receipt no      amount
    venkat                         raj                         1102          10000
    ramu                          ramesh                   1102         20000
    here both receipt no is same.now i want to select one of this receipt and click pay button which is place in outside the grid.
    now my need is after click the pay button in text box i need 10000+20000=30000,after click that button i want both receipts should be invisible...'
    how i will do this,
    any suggession,
    Thanks
    B.venkatesan

    One way with 10g:
    select mgr,
           rtrim(xmlagg(xmlelement(empno,empno||',').extract('//text()')),',')  emps
    from emp
    where mgr is not null
    group by mgr;10g:
    -- define this function:
    create or replace
    function concatenate(c Sys_refcursor, sep varchar2 default null) return varchar2
    as
      val varchar2(100);
      return_value varchar2(4000);
    begin
    --  open c;
      loop
      fetch c into val;
      exit when c%notfound;
      if return_value is null then
        return_value:=val;
      else
        return_value:=return_value||sep||val;
      end if;
      end loop;
      return return_value;
    end;
    select mgr,
           concatenate(cursor(select empno from emp e where e.mgr=emp.mgr order by empno),',')
    from emp
    where mgr is not null
    group by mgr;With 11g:
    select mgr,
           listagg(empno,',') within group (order by empno) emps
    from emp
    where mgr is not null
    group by mgr;

  • Why "select count(*) from sometable" will get 2 rows in ResultSet?

    When i query this sql string.. the resultset returns 2 rows.
    and when i use such code as following :
    while (rs.next())
    temp = rs.getString(1);
    will cause an error as: the course is outOfRang...
    what's the matter with this statement?

    When i query this sql string.. the resultset returns 2
    rows.
    and when i use such code as following :
    while (rs.next())
    temp = rs.getString(1);
    will cause an error as: the course is outOfRang...
    what's the matter with this statement?
    Do you have a printStackTrace in your code to determine the exact line where you get the error?

  • How to get multiple row data in single row for one value of foreign key

    i want to get data from a table in a way that all the emp_id corresponding to one manager_id
    in employee table come in one row. (emp_id is the primary key and manager_id is the foreign key) Since there are different emp_id whose manager_id is same
    so how can i get all the emp_id in one row .

    One way with 10g:
    select mgr,
           rtrim(xmlagg(xmlelement(empno,empno||',').extract('//text()')),',')  emps
    from emp
    where mgr is not null
    group by mgr;10g:
    -- define this function:
    create or replace
    function concatenate(c Sys_refcursor, sep varchar2 default null) return varchar2
    as
      val varchar2(100);
      return_value varchar2(4000);
    begin
    --  open c;
      loop
      fetch c into val;
      exit when c%notfound;
      if return_value is null then
        return_value:=val;
      else
        return_value:=return_value||sep||val;
      end if;
      end loop;
      return return_value;
    end;
    select mgr,
           concatenate(cursor(select empno from emp e where e.mgr=emp.mgr order by empno),',')
    from emp
    where mgr is not null
    group by mgr;With 11g:
    select mgr,
           listagg(empno,',') within group (order by empno) emps
    from emp
    where mgr is not null
    group by mgr;

Maybe you are looking for