Getting Parent Node using SQL

Hello,
I am trying to query an XML which is stored in XMLTYPE datatype column in oracle table. I am using the below SQL:
select
EXTRACTVALUE (column_name, '/Person/Customer/Customer_First_Name'),
EXTRACTVALUE (column_name, '/Person/Customer/Customer_Last_Name'),
from TABLE_1 A, TABLE ( XMLSEQUENCE (EXTRACT (A.column_name, '/sdi_header//Person')) ) P
Sample XML:
<sdi_header>
<Person>
<Customer_First_Name>ABC</Customer_First_Name>
<Customer_Last_Name>DEF</Customer_First_Name>
</Person>
<warehouse>
<Person>
<Customer_First_Name>XYZ</Customer_First_Name>
<Customer_Last_Name>MNO</Customer_First_Name>
</Person>
</warehouse>
</sdi_header>
In the above query the Alias P has a //Person which means I am trying to extract all the repeating person Nodes information in XML. Retrieving all persons is working but I want to extract the parent node information of each Person like for Example in the above sample XML, it has two persons in it
1) 1 Person is coming under sdi_header node , in such case I need to get <sdi_header/> in SELECT statement
2) 1 Person is coming under warehouse node , in such case I need to get <warehouse/>in SELECT statement
How can the parent node information be extracted in SELECT statement.
Any suggestion/Help is much appreciated.
Thanks,
SKM
Edited by: user9116854 on Mar 1, 2010 10:24 AM
Edited by: user9116854 on Mar 1, 2010 10:30 AM
Edited by: user9116854 on Mar 1, 2010 10:35 AM
Edited by: user9116854 on Mar 1, 2010 10:45 AM
Edited by: user9116854 on Mar 2, 2010 8:05 AM

Sounds like you are looking for something like this
Connected to Oracle Database 11g Enterprise Edition Release 11.1.0.6.0
SQL> WITH table_1 AS
  2  (SELECT XMLTYPE('<sdi_header>
  3  <Person>
  4  <Customer_First_Name>ABC</Customer_First_Name>
  5  <Customer_Last_Name>DEF</Customer_Last_Name>
  6  </Person>
  7  <warehouse>
  8  <Person>
  9  <Customer_First_Name>XYZ</Customer_First_Name>
10  <Customer_Last_Name>MNO</Customer_Last_Name>
11  </Person>
12  </warehouse>
13  </sdi_header>') column_name
14     FROM dual)  -- WITH simulates your table I do not have
15  select t1.*
16    from TABLE_1,
17         XMLTABLE('for $i in /sdi_header//Person
18                     return <root>
19                           {$i/Customer_First_Name,
20                           $i/Customer_Last_Name}
21                           <parent>{$i/../name()}</parent>
22                      </root>'
23                  PASSING table_1.column_name
24                  COLUMNS
25                  fname   VARCHAR2(20) PATH 'Customer_First_Name',
26                  lname   VARCHAR2(20) PATH 'Customer_Last_Name',
27                  pnode   VARCHAR2(20) PATH 'parent') t1;
FNAME                LNAME                PNODE
ABC                  DEF                  sdi_header
XYZ                  MNO                  warehouseYou can find out how formatted that message by looking in the FAQ in the upper right. It uses the { code } tag (without spaces).

Similar Messages

  • How to get this output using sql query?

    Hi,
      How to get this output using sql query?
    Sno Name Age ADD Result
    1 Anil 23 delhi Pass
    2 Shruti 25 bangalor Pass
    3 Arun 21 delhi fail
    4 Sonu 23 pune Pass
    5 Roji 26 hydrabad fail
    6 Anil 28 delhi pass
    Output
    Sno Name Age ADD Result
    1 Anil 23 delhi pass
    28 delhi pass

    Hi Vamshi,
    Your query is not pretty clear.
    write the select query using Name = 'ANIL' in where condition and display the ouput using Control-break statements.
    Regards,
    Kannan

  • Getting Parent Node On tree Issue..

    Hi,
    I Have Constructed a Tree and i am Able to get the Details of the clicked Node on the Tree into the Backing Bean.
    But I'm unable to get the Parent Node of the Clicked Child Node.
    Ex:On Click of Employee(Child Node) in the Tree, I should get the Department (Parent Node) in Backing Bean.
    I'm able to get only the details in the same Level of Tree Node(ie All Employees in the Selected Employee Level).
    IDE: JDeveloper 10.1.3.2.
    Please Suggest me.
    Thanking You,
    Bandaru.

    Sounds like you are looking for something like this
    Connected to Oracle Database 11g Enterprise Edition Release 11.1.0.6.0
    SQL> WITH table_1 AS
      2  (SELECT XMLTYPE('<sdi_header>
      3  <Person>
      4  <Customer_First_Name>ABC</Customer_First_Name>
      5  <Customer_Last_Name>DEF</Customer_Last_Name>
      6  </Person>
      7  <warehouse>
      8  <Person>
      9  <Customer_First_Name>XYZ</Customer_First_Name>
    10  <Customer_Last_Name>MNO</Customer_Last_Name>
    11  </Person>
    12  </warehouse>
    13  </sdi_header>') column_name
    14     FROM dual)  -- WITH simulates your table I do not have
    15  select t1.*
    16    from TABLE_1,
    17         XMLTABLE('for $i in /sdi_header//Person
    18                     return <root>
    19                           {$i/Customer_First_Name,
    20                           $i/Customer_Last_Name}
    21                           <parent>{$i/../name()}</parent>
    22                      </root>'
    23                  PASSING table_1.column_name
    24                  COLUMNS
    25                  fname   VARCHAR2(20) PATH 'Customer_First_Name',
    26                  lname   VARCHAR2(20) PATH 'Customer_Last_Name',
    27                  pnode   VARCHAR2(20) PATH 'parent') t1;
    FNAME                LNAME                PNODE
    ABC                  DEF                  sdi_header
    XYZ                  MNO                  warehouseYou can find out how formatted that message by looking in the FAQ in the upper right. It uses the { code } tag (without spaces).

  • How to get Parent nodes and corresponding child nodes in BI Hierarchy

    Hi all,
    I have a standard function module 'RSNDI_SHIE_STRUCTURE_GET3'  to get child node if i pass parent node. But I need child nodes along with the provided parent node as I use this in a loop in BI.
    Thanks

    Could any one help me in this regards .
    Thanks in advance
    Regards,
    sri

  • Get Parent node from Base member

    Hi ,
    My user select base member from CV .
    I want parent node for that base member .
    I am using =EVPRO( App name , memmber id , "PARENTH1" ) .
    I am not getting parent member from this funcation .
    Pls let me know any other way for this ?
    regards,
    PSR

    Hi,
    EVPRO for getting the value for PARENTH1 of any member should work. Please check whether you have included all the parameters of this function inside double quotes.
    EVPRO("APPNAME","MEMBER_ID","PROPERTY")
    Hope this helps,
    Regards,
    G.Vijaya Kumar

  • Getting child nodes using sax

    How can i get the value of childnodes in java using sax?

    Just wait a while. The child nodes will be passed to you after the parent nodes. Of course, you will have to keep track of which child nodes of which parent elements you want, but you probably know this already. If you want to process the entire file first and then decide which child nodes are of interest, read up on one of the DOM-ish approaches.
    Dave Patterson

  • HOw to get parent node name value through its child node?

    Hi,
    Experts,
    I am able to get child node name values but according to attribute name value i want to  get its parent name value how to achieve that. For that i have used If_Ixml_element->Get_parent. Please pass some idea on it.
    Thanks in advance,
    Shabeer ahmed.

    Hello Shabeer
    I think the coding should be straightforward:
    DATA: lo_element   TYPE REF TO if_ixml_element,
              lo_child        TYPE REF TO if_ixml_node,
              lo_parent      TYPE REF TO if_ixml_node.
    " NOTE: LO_ELEMENT holds your child node
      lo_child ?= lo_element.
      lo_parent = lo_child->get_parent( ).
    Regards
      Uwe

  • Get a date using Sql

    hi
    how i can get the following date using sql, ie i want to get '01-APR-2005'
    if the sysdate is between (01/04/2005 - 31/3/2006). in the same way if it is
    01/04/2004 - 31/3/2005 i want to get '01-apr-2004'...in the same way for any year..
    how i can get this...
    thx in adv
    Kris
    Message was edited by:
    Kris

    SQL> select dt, add_months(trunc(add_months(dt, -3), 'yyyy'), 3) new_dt
      2    from t
      3   order by dt;
    DT        NEW_DT
    01-APR-04 01-APR-04
    31-DEC-04 01-APR-04
    01-JAN-05 01-APR-04
    31-MAR-05 01-APR-04
    01-APR-05 01-APR-05
    31-DEC-05 01-APR-05
    01-JAN-06 01-APR-05
    31-MAR-06 01-APR-05
    8 rows selected.
    SQL> select add_months(trunc(add_months(sysdate, -3), 'yyyy'), 3) from dual;
    ADD_MONTH
    01-APR-05

  • Using xpath to get parent nodes

    hi! i�m trying to copy some elements from a xml file, and i have some problems.
    i have this file
    ?xml version="1.0" encoding="UTF-8"?>
    <?xml-stylesheet type="text/xsl" href="xslpath.xsl"?>
    <bookstore>
    <book id="0">
    <title id="pt">Harry Magico</title>
    <desc id="1">
    <price id="3">29.99</price>
    <price1 id="3">329.95</price1>
    </desc>
    <name>nome</name>
    </book>
    </bookstore>
    i�m using a xsl to copy the nodes.
    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:template match="/">
    <xsl:copy-of select="/bookstore/book/title/ancestor-or-self::price1"/> <!--not correct-->
    </xsl:template>
    </xsl:stylesheet>
    well, if i select price1 node, what i want to get is:
    <?xml version="1.0" encoding="utf-8"?>
    <bookstore>
    <book id="0">
    <desc id="1">
    <price1 id="3">329.95</price1>
    </desc>
    </book>
    </bookstore>
    i just want copy the node without is "brothers" :) and with is parents.
    can anyone help me?

    hi! i�m trying to copy some elements from a xml file,
    and i have some problems.
    i have this file
    ?xml version="1.0" encoding="UTF-8"?>
    <?xml-stylesheet type="text/xsl"
    href="xslpath.xsl"?>
    <bookstore>
    <book id="0">
    <title id="pt">Harry Magico</title>
    <desc id="1">
    <price id="3">29.99</price>
    <price1 id="3">329.95</price1>
    </desc>
    <name>nome</name>
    </book>
    </bookstore>
    i�m using a xsl to copy the nodes.
    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">
    <xsl:template match="/">
    <xsl:copy-of
    select="/bookstore/book/title/ancestor-or-self::price
    "/> <!--not correct-->
    </xsl:template>
    l:stylesheet>
    well, if i select price1 node, what i want to get
    is:
    <?xml version="1.0" encoding="utf-8"?>
    <bookstore>
    <book id="0">
    <desc id="1">
    <price1 id="3">329.95</price1>
    </desc>
    </book>
    </bookstore>
    i just want copy the node without is "brothers" :)
    and with is parents.
    can anyone help me?right off my head, try this:
    /bookstore/book/title/desc/price1/ancestor-or-self::*

  • Hierarchy  Query  to  get  parent  nodes?

    Hi Everyone,
    I want to write a hierarchy query which should give me the path starting from given node to its parents(Grand parents). below is the sample data and the output what i am expecting. and also the output what i am getting right now from my query.
    CREATE TABLE RELATION (PARENT VARCHAR2(5),CHILD VARCHAR2(5) PRIMARY KEY);
    --Data for the tree which starts from the root 'A'
    Insert into RELATION (PARENT, CHILD) Values (NULL,'A');
    Insert into RELATION (PARENT, CHILD) Values ('A', 'B');
    Insert into RELATION (PARENT, CHILD) Values ('A', 'C');
    Insert into RELATION (PARENT, CHILD) Values ('B', 'D');
    Insert into RELATION (PARENT, CHILD) Values ('B', 'E');
    Insert into RELATION (PARENT, CHILD) Values ('D', 'F');
    Insert into RELATION (PARENT, CHILD) Values ('C', 'G');
    --Data for the tree which starts from the root 'H'
    Insert into RELATION (PARENT, CHILD) Values (NULL,'H');
    Insert into RELATION (PARENT, CHILD) Values ('H', 'I');
    Insert into RELATION (PARENT, CHILD) Values ('H', 'J');
    Expected Output by passing values as 'F' which gives the path from bottom to up.
    A<-B<-D<-F
    My Query:
    SELECT substr(sys_connect_by_path(child,'<-'),3)
    FROM relation
    WHERE connect_by_isleaf = 1
    START WITH child = 'F'
    CONNECT BY PRIOR parent = child
    ORDER BY child;
    Output of my query:
    F<-D<-B<-A
    I am getting the output in reverse order. i can use the reverse string function to reverse the string but the problem is the node can also contain the values like 'AC' 'BA'.. in future.
    Can anyone please help me in getting the correct output.
    Thank you in advance.

    I like ListAgg :D
    with RELATION(PARENT,CHILD) as(
    select NULL,'A' from dual union all
    select 'A', 'B' from dual union all
    select 'A', 'C' from dual union all
    select 'B', 'D' from dual union all
    select 'B', 'E' from dual union all
    select 'D', 'F' from dual union all
    select 'C', 'G' from dual union all
    select NULL,'H' from dual union all
    select 'H', 'I' from dual union all
    select 'H', 'J' from dual)
    SELECT ListAgg(child,'<-')
           within group(order by Level desc) as revPath
    FROM relation
    START WITH child = 'F'
    CONNECT BY PRIOR parent = child;
    revPath
    A<-B<-D<-F

  • Re: Hierarchy  Query  to  get  parent  nodes?

    Guys i need a help here please....
    i want to query using any single value for example in where clause for  "E" , i want to retrieve whole bunch from "A" to "G" which are all interlinked. is there any way for  this?..
    im lookking like
    A
    B
    C
    D
    E
    F
    G
    when i query for "E"
    Thanks in advance..

    sorry,,, i couldn't explain properly...
    here is the example...
    CREATE TABLE RELATION (PARENT VARCHAR2(5),CHILD VARCHAR2(5) PRIMARY KEY);
    ---this is group 1
    Insert into RELATION (PARENT, CHILD) Values ('A', 'B');
    Insert into RELATION (PARENT, CHILD) Values ('A', 'C');
    Insert into RELATION (PARENT, CHILD) Values ('B', 'D');
    Insert into RELATION (PARENT, CHILD) Values ('B', 'E');
    Insert into RELATION (PARENT, CHILD) Values ('D', 'F');
    Insert into RELATION (PARENT, CHILD) Values ('C', 'G');
    --This is group 2
    Insert into RELATION (PARENT, CHILD) Values ('H', 'I');
    Insert into RELATION (PARENT, CHILD) Values ('H', 'J');
    Insert into RELATION (PARENT, CHILD) Values ('J', 'K');
    Insert into RELATION (PARENT, CHILD) Values ('K', 'M');
    I WILL TAKE  group 1 ..
    i want from relation table single  column all related falling in one group . like..
    when i look for E i should get all the below..
    A
    B
    C
    D
    E
    F
    G
    even though E is not directly linked to A it is linked through B. basically all in one group but the link is not direct. i dont have any group key in my table..
    the query column (where clause) can be either parent or child..
    hope u will gettit..   thanks for ur patience...

  • How to get partition key using SQL

    I want to get the subpartition key of a Rang-List partition table in program.
    How to write the SQL.
    Thanks.

    Can you query against dba_tab_partitions & dba_part_key_columns?
    Edit: Misread the question, didnt see SUBpartitions. More coffee, less posting for me.
    Edited by: mrk on Dec 22, 2011 9:10 AM

  • SRM Get parent node

    Dear experts,
    I need to know a FM or BAPI in order to know the parent objetc/record/document that contains an element.
    SAP provides the BAPI BAPI_RECORD_GETELEMENTS to get the elements of a record, but I need the opposite operation (get the record that contains the element).
    Thanks in advance.
    Best regards,
    A. Cepa

    Hi,
    EVPRO for getting the value for PARENTH1 of any member should work. Please check whether you have included all the parameters of this function inside double quotes.
    EVPRO("APPNAME","MEMBER_ID","PROPERTY")
    Hope this helps,
    Regards,
    G.Vijaya Kumar

  • Finding parent node using hierarchical query

    * Is it possible to find the parent record for a given child record in Oracle 8i using hierarchical queries?
    * For instance, if I have the following table:MyTable
    col1
    col2
    col3* The following query returns the tree structure:SELECT *
      FROM MyTable
    START WITH col1 is null
    CONNECT BY PRIOR col1 = col2* Is it possible to retrieve the root record (col1 is null) for a given child record?
    * Appreciate any pointers.

    Hi,
    Just change the condition for "Connect by Prior" and it will start giving you bottom-to-top records.
    Your Original Query
    SELECT * FROM MyTable START WITH col1 is nullCONNECT BY PRIOR col1 = col2
    change is like this,
    SELECT * FROM MyTable START WITH col1=<Value> CONNECT BY PRIOR col2 = col1
    Replace <Value> by the actual value of field.
    HTH,
    Kalpen.

  • Get JAAS Credentials using SQL.

    Hello everyone,
    I'm using JDeveloper 11.1.1.3. I was wondering if there's a way to retrieve certain JAAS information from my application using an SQL query. For example, if i had multiple users, and every user has the authority to add a new row in the database through my application. Is there a way like the the concept of a TIMESTAMP to know which user inserted a certain row at a specific date?
    Thanks,
    Mohamed.

    Mohammed,
    you might want to look into history columns. Sample http://adftraining.com/how-to-use-history-columns-in-oracle-adf-for-mini-auditing
    Timo

Maybe you are looking for

  • XML Transformation Problem in JDeveloper 10.1.3

    I am trying to transform an XML using an XSL, by a Java program, which uses javax.xml.transform.Transformer. I have a Java project which has the above said program, where when i run the program, the xml transformation is done successfully. But I have

  • Miro line item quantity and amount after miro

    Dear Forum, I have got the help about this subject and quite clear. Thanks for all have helped. Now I need to confirm 1 more part. Assuming in PO there are 2 scenarios where gr based iv is ticked and also not ticked, after both GR and miro done (comp

  • How to build dynamic menus using JSP==Urgent==Please Help me

    Hello, I have exhausted searching on internet to find a book which tells how to build Dynmic menus in JSP.I dont want to use DHTML as this becomes complex as the menu categories are built using data from database.Is there any workaround in java to do

  • 6014 encoder

    Dear all I have to read an encoder that measures the angular position with signals A and B only (so no index Z). I use windows XP with labview 2011 and an acquisition card NI 6014. I have been able to count the individual signals with the application

  • How to read client certificate after SSL has be established

    Hi, Folks: I've established mutual authentication between client and server, how do I go about reading the client certificate on the server side after SSL session has been established? Basically I am trying to read the client name from the client cer