Query for Hierarchy Path from child to parent for a given child key by user

CREATE TABLE EMP_ID
  HEAD_ID  NUMBER(4),
  TAIL_ID  NUMBER(4),
  NAME     VARCHAR2(20 )
Insert into EMP_ID  Values  (1011, 1008, 'C11');
Insert into EMP_ID  Values  (1008, 1003, 'C8');
Insert into EMP_ID  Values  (1012, 1003, 'C12');
Insert into EMP_ID  Values  (1020, 1003, 'C20');
Insert into EMP_ID  Values  (1025, 1003, 'C25');
Insert into EMP_ID  Values  (1015, 1012, 'C15');
Insert into EMP_ID  Values  (1012, 1005, 'C12');
Insert into EMP_ID  Values  (1005, 1017, 'C5');
COMMIT;now my requirement is like this
if choose the head_id as 1012 and tail_id as 1017
it should traverse the path form tail to head and print the path as shown below
c12/c5/c17/c12such that it shows that tail_id has been used as head_id in the same hierarchy path previously.
here the hierarchy is as shown below
1015
      1012
            1005
                1017

Rede,
Is this what you want?
CREATE TABLE EMP_ID
  HEAD_ID  NUMBER(4),
  TAIL_ID  NUMBER(4),
  NAME     VARCHAR2(20 )
Insert into EMP_ID  Values  (1011, 1008, 'C11');
Insert into EMP_ID  Values  (1008, 1003, 'C8');
Insert into EMP_ID  Values  (1012, 1003, 'C12');
Insert into EMP_ID  Values  (1020, 1003, 'C20');
Insert into EMP_ID  Values  (1025, 1003, 'C25');
Insert into EMP_ID  Values  (1015, 1012, 'C15');
Insert into EMP_ID  Values  (1012, 1005, 'C12');
Insert into EMP_ID  Values  (1005, 1017, 'C5');
Insert into EMP_ID  Values  (1017, 1012, 'C17');  ---- ==== This was missing in your setup example
COMMIT;QUERY and OUTPUT
SELECT *
  FROM (
select
  connect_by_iscycle as CYC
,dt.head_id
,dt.tail_id                     
,sys_connect_by_path
                  (  dt.name
                  ) AS EMP_PATH                   
from   emp_id dt
start with dt.head_id = 1012
connect by  NOCYCLE  dt.head_id= prior dt.tail_id)
CYC     HEAD_ID     TAIL_ID     EMP_PATH
0     1012     1003     /C12
0     1012     1005     /C12
0     1005     1017     /C12/C5
1     1017     1012     /C12/C5/C17
0     1012     1003     /C12/C5/C17/C12If you just want the PATH printed
SELECT *
  FROM (
select     
max(sys_connect_by_path
                  (  dt.name
                  )) AS EMP_PATH                   
from   emp_id dt
start with dt.head_id = 1012
connect by  NOCYCLE  dt.head_id= prior dt.tail_id)
/C12/C5/C17/C12vr,
Sudhakar B.

Similar Messages

  • How to find the name of query for a given report

    Hi All,
    I am having the name of a report and i need to find out the name of query for that report . Plz tell me how to find out the name of the query for a given report.
    Thanks.
    Regards,
    Pooja Joshi.

    Use this FM
    RSAQ_DECODE_REPORT_NAME
    This FM takes program name as I/P and gives Query Name as O/P.
    This FM uses the structure AQADEF to fetch the data.
    Hope this helps.
    Regards
    Vinayak

  • Query for Drop Down By key

    Hi,
    Explaining my problem with an example.
    There is a hotel table where user enter hotel details
    Like City, Dep Date, Arr Date, No of Days , rate  etc  and these in turn get saved to table say USER_HOTEL_DETAILS  . When user comes to his plan/entered details again, previously saved data is shown to him.
    For making a selection for City I have to give a dropdown to user with cities list that are maintained in other table say HOTEL_DATA which has city, rate, and currency fields and city is the key of table.
    Now if I use drop down by key or index for city I need to fetch city values from table HOTEL_DATA and have to populate context of city field of USER_HOTEL_DETAILS.
    For dropdown my value text is going to be city .For key if I try to give serial numbers say 1, 2, 3 as key for populating dropdown, the key will get stored in database table against city name. To avoid this while saving data I have to write additional code while saving and retrieving data that take value against selected key.
    To avoid this one way is to use city name as both Key and Value. What is the other alternative I can use for? Please help
      Regards,
      Madhvika

    Hi ,
    It is better to have citykey in HOTEL table and maintain a text table for the same.This is good approach.
    Because tommorow if city needs to be displayed in other text also just adding the same in the text table would be suffice.
    For city texts retrieve it from text table and bind to the node.
    Regards,
    Madhu

  • How to write a query for the given scenario ?

    Hi All ,
    I am having two tables EMP, DEPT with the below data.
    EMP TABLE :--
    EID     ENAME     JOB     SAL     DEPID
    111     RAM     MANAGER     1500     10
    222     SAM     ASST MANAGER     2000     20
    333     KALA     CLERK     2500     10
    444     BIMA     MANAGER     3000     20
    555     CHALA     MANAGER     3500     30
    666     RANI     ASST MANAGER     4000     10
    777     KAMAL     MANAGER     2400     10
    DEPT TABLE :--
    DEPID     DNAME
    10     XX
    20     YY
    30     ZZ
    Q1 : I want the sum of salary of each department and for the particular job . Here in each departmant manager, asst. manager, clerk posts are there .
    I want to display the result like below ....
    JOB     10     20     30
    MANAGER     3900     3000     3500
    ASST MANAGER 4000     2000     NULL
    CLERK     2500     NULL     NULL
    please tell me how to write a sql query ?
    Thanks
    Sai

    In general case, you cannot write this query.
    This is one of the limits of relational database concepts. The number of columns must be known up-front. In the SELECT clause, you have to list and name all columns returned by the query. So you have to know number of departments. (There are some workarounds - you can return one column with concatenated values for all departments, separated by space character).
    If you know that you have 3 departments then you qurey will return 4 columns:
    SELECT
       e.job,
       SUM ( CASE WHEN d.deptid = 10 THEN e.sal ELSE NULL END) d10,
       SUM ( CASE WHEN d.deptid = 20 THEN e.sal ELSE NULL END) d20,
       SUM ( CASE WHEN d.deptid = 30 THEN e.sal ELSE NULL END) d30
    FROM dept d, emp e
    WHERE d.deptno = e.deptno
    GROUP BY e.job

  • Customizing a query for a report according to login user name

    Hi, I am new to the portal, so I have a urgent question:
    In my company we have local departments who are supposed to use
    the same report but only with their own data.
    I have a table with all users and their parameters (e.g.
    username + deptno) and might be able to create a function which
    gets the username (found that in one of the standard packages)
    and retrieves the parameter from the database via SELECT. The
    function should then return the parameter to be used where ever
    needed.
    Big question: How can I use this function in a SELECT-Statement
    for my report? I guess it must be something like
    SELECT * FROM -table or view- WHERE deptno = -schema.function-
    Right? Does the function have to be part of a package?
    Thanks in advance for any help.
    Yours
    Reinhard Piper
    Munich / Germany

    the table or view is WWSEC_person this is where the users are..
    Ruud

  • How to write query for this given information???

    I have table (employees) like this
    Hire_date
    Salary
    04-jan-1991
    2000
    05-mar-1991
    1300
    12-sep-1991
    2400
    19-feb-1992
    3000
    17-apr-1992
    1000
    23-nov-1992
    1200
    25-jan-1993
    1000
    06-jun-1993
    1200
    I want  to get output like this
    Hire_date
    Salary
    Years in range
    total
    04-jan-1991
    2000
    05-mar-1991
    1300
    12-sep-1991
    2400
    01-jan-1991 to 31-dec-1991
    5700
    19-feb-1992
    3000
    17-apr-1992
    1000
    23-nov-1992
    1200
    01-jan-1992 to 31-dec-1992
    4200
    25-jan-1993
    1000
    06-jan-1993
    1200
    01-jan-1993 to 31-dec-1993
    2200
    give me some ideas guys

    Without using analytic functions,
    select
         hire_date,salary,
         decode(hire_date,null,extract(year from hire_date)) year_tag,
         decode(hire_date,null,sum(salary)) total_sal
    from
         employees
         group by grouping sets ((hire_date,salary,extract(year from hire_date)),extract(year from hire_date),())
    Output
    HIRE_DATE    SALARY  YEAR_TAG TOTAL_SAL
    04-JAN-91      2000
    05-MAR-91      1300
    12-SEP-91      2400
                             1991      5700
    19-FEB-92      3000
    17-APR-92      1000
    23-NOV-92      1200
                             1992      5200
    25-JAN-93      1000
    06-JUN-93      1200
                             1993      2200
                                      13100

  • Query for Order recomendation from MRP.

    Good evening,
    Recommendations are saved for the Production and Purchase Order after MRP is done.  New Production and/or Purchase Orders are created in Planned stages.  We need a query for the Alert Management to the users for the new Orders created.
    Please can anyone guide and help me.
    thank you.

    Hi,
    Welcome you post on the forum.
    Try this for production order:
    SELECT T0.DocNum, T0.ItemCode FROM OWOR T0
    WHERE T0.OriginType = 'R' AND DateDiff(dd,T0.DocDate,GetDate())=0
    Thanks,
    Gordon
    Good Morning Sir,
    Thanks for your message, guidance and support for the query.
    The query for the alert for Production is working fine, we just changed the DocDate to PostDate as the Production Order, Posting date is as PostDate.
    We tried to change the OWOR to OPOR and the Origin type to T0.Comments='Origin :MRP' and tried for Purchase Order, but the alert is not visible.  Would it be ok, that we create an UDF and try the same?.
    thanks and warm regards.

  • Query for all hours in a month?

    Hello,
    I was hoping someone might be able to assist. I need to query for all the hours in a user specified date range (generally a month). For example,
    a query such as:
    select all hr_end from dual where start_date between '01-feb-2010' and '28-feb-2010'
    that returns:
    feb 01 2010 01:00
    feb 01 2010 02:00
    feb 01 2010 03:00
    feb 28 2010 23:00
    feb 28 2010 24:00
    Ideally, I want to be able to run this query within a WITH clause such that I can reference the temporary table/ list of hours in a subsequent select statement quickly. Something like:
    With
    all_hrs_in_month AS
    select .....
    where start_date between '01-mar-2010' and '31-mar-2010'
    I've looked around for similar questions, but have only found ones for all the 'days' in a month using level, connect by, row_num, for which I'm honestly not too familiar with and wasn't clear as to how I could modify to my needs.
    Greatly appreciate your help with this request.
    - j
    Edited by: user12942939 on Apr 5, 2010 12:04 PM

    Hi,
    Welcome to the forum!
    WITH     got_parameters  AS
         SELECT     TO_DATE ('01-mar-2010 00:00', 'dd-mon-yyyy hh24:mi')     AS start_date
         ,     TO_DATE ('31-mar-2010 23:00', 'dd-mon-yyyy hh24:mi')     AS end_date
         FROM     dual
    ,     all_hrs          AS
         SELECT     start_date + ( (LEVEL - 1)
                        / 24
                        )     AS hr
         FROM    got_parameters
         CONNECT BY     LEVEL <= 1 + ( 24
                                   * (end_date - start_date)
    SELECT       TO_CHAR (hr, 'DD-Mon-YYYY HH24:MI')     AS h
    FROM       all_hrs
    ORDER BY  hr
    ;Output:
    H
    01-Mar-2010 00:00
    01-Mar-2010 01:00
    01-Mar-2010 02:00
    01-Mar-2010 03:00
    31-Mar-2010 22:00
    31-Mar-2010 23:00Notice that start_date and end_date don't have to span then entire month; they don't even have to be in the same month.
    If you'd rather specify just one parameter (such as a single string containing the month and year):
    WITH     got_parameters  AS
         SELECT     TRUNC ( TO_DATE (:p_month, 'mon-yyyy')
                    , 'MONTH'
                    )          AS start_date
         ,     TRUNC ( ADD_MONTHS ( TO_DATE (:p_month, 'mon-yyyy')
                                 , 1
                    , 'MONTH'
                    )          AS end_date
         FROM     dual
    ,     all_hrs          AS
         SELECT     start_date + ( (LEVEL - 1)
                        / 24
                        )     AS hr
         FROM    got_parameters
         CONNECT BY     LEVEL <= ( 24          -- NOTE: Not adding 1 here
                               * (end_date - start_date)
    SELECT       TO_CHAR (hr, 'DD-Mon-YYYY HH24:MI')     AS h
    FROM       all_hrs
    ORDER BY  hr
    How It Works
    SELECT  LEVEL  AS n
    FROM    dual
    CONNECT BY  LEVEL <= x
    ;Produces a result set consiting of the integers 1, 2, 3, ..., x.
    There's nothing magical about the dual table; you can use any table AS LONG AS THE TABLE HAS ONLY ONE ROW .
    The other examples you saw probably just added this to a starting date, to get successive days, since, in Oracle date arithmetic, dt+n is a DATE n days after dt.
    Your case is slightly more complicated, because you want to add hours, not days. Since an hour is 1/24 of a day, we multiply by 24 to find how many integers to genereate, and divide by 24 when adding that number to the base date.
    Edited by: Frank Kulash on Apr 5, 2010 3:07 PM

  • How to find the cpu usage per query for a time period

    Hi All,
    Is there a way to find the cpu used per query for a given time period?
    DB:10.2.0.5
    OS:AIX
    Thanks

    user13364377 wrote:
    if there are multiple queries starting at the same time, then what to do?Handle:      user13364377
    Status Level:      Newbie (10)
    Registered:      Jul 5, 2010
    Total Posts:      264
    Total Questions:      113 (84 unresolved)
    why so many unanswered questions?
    clarify your question
    same SQL multiple times from different sessions?
    or
    different SQLs from different sessions?

  • Day wise Closing stocks for the given month

    Hi,
    Please suggest me your valuable ideas for Closing Stocks Calender day wise for the given month.
    Ex : User Input 03.2013 , now report has to show daywise closing stock like below
                                            01.03.2013    140 MT
                                             02.03.2013     150 MT
                                              31.03.2013    230 MT.

    I like recursive with clause B-)
    with rec(StaV) as(
    select extract(day from date '2011-01-01')
      from dual
    union all
    select StaV+1
      from rec
    where StaV+1 <= extract(day from last_day(date '2011-01-01')))
    select ListAgg('''' || to_char(StaV) || '''',' ')
           within group(order by StaV) as days
    from rec;
    DAYS
    '1' '2' '3' '4' '5' '6' '7' '8' '9' '10' '11' '12' '13' '14' '15' '16' '17' '18' '19' '20' '21' '22' '23' '24' '25' '26' '27' '28' '29' '30' '31'

  • Optimal read write performance for data with duplicate keys

    Hi,
    I am constructing a database that will store data with duplicate keys.
    For each key (a String) there will be multiple data objects, there is no upper limit to the number of data objects, but let's say there could be a million.
    Data objects have a time-stamp (Long) field and a message (String) field.
    At the moment I write these data objects into the database in chronological order, as i receive them, for any given key.
    When I retrieve data for a key, and iterate across the duplicates for any given primary key using a cursor they are fetched in ascending chronological order.
    What I would like to do is start fetching these records in reverse order, say just the last 10 records that were written to the database for a given key, and was wondering if anyone had some suggestions on the optimal way to do this.
    I have considered writing data out in the order that i want to retrieve it, by supplying the database with a custom duplicate comparator. If I were to do this then the query above would return the latest data first, and I would be able to iterate over the most recent inserts quickly. but Is there a performance penalty paid on writing to the database if I do this?
    I have also considered using the time-stamp field as the unique primary key for the primary database instead of the String, and creating a secondary database for the String, this would allow me to index into the data using a cursor join, but I'm not certain it would be any more performant, at least not on writing to the database, since it would result in a very flat b-tree.
    Is there a fundamental choice that I will have to make between write versus read performance? Any suggestions on tackling this much appreciated.
    Many Thanks,
    Joel

    Hi Joel,
    Using a duplicate comparator will slow down Btree access (writes and reads) to
    some degree because the comparator is called a lot during searching. But
    whether this is a problem depends on whether your app is CPU bound and how much
    CPU time your comparator uses. If you can avoid de-serializing the object in
    the comparator, that will help. For example, if you keep the timestamp at the
    beginning of the data and only read the one long timestamp field in your
    comparator, that should be pretty fast.
    Another approach is to store the negation of the timestamp so that records
    are sorted naturally in reverse timestamp order.
    Another approach is to read backwards using a cursor. This takes a couple
    steps:
    1) Find the last duplicate for the primary key you're interested in:
      cursor.getSearchKey(keyOfInterest, ...)
      status = cursor.getNextNoDup(...)
      if (status == SUCCESS) {
          // Found the next primary key, now back up one record.
          status = cursor.getPrev(...)
      } else {
          // This is the last primary key, find the last record.
          status = cursor.getLast(...)
      }2) Scan backwards over the duplicates:
      while (status == SUCCESS) {
          // Process one record
          // Move backwards
          status = cursor.getPrev(...)
      }Finally another approach is to use a two-part primary key: {string,timestamp}.
    Duplicates are not configured because every key is unique. I mention this
    because using duplicates in JE has more overhead than using a unique primary
    key. You can combine this with either of the above approaches -- using a
    comparator, negating the timestamp, or scanning backwards.
    --mark                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Print parent to child link or path from the same table

    create table dummy(nodeid number, parentid number, nodename varchar2(20));
    insert into dummy values(100,-1,'homegoods');
    insert into dummy values(101,100,'kitchen');
    insert into dummy values(102,101,'skillet');
    select * from dummy gives:
    nodeid     parentid   node_name
    100         -1         HOMEGOODS
    101         100       KITCHEN
    102         101       SKILLETnote: parent id is the node id in the same table except for the top node.
    select nodeid, nodename, 'i want complete path from parent to child here' as path from dummy where nodeid = 102
    expected result
    nodeid   name     path
    102       skillet     homegoods>kitchen>skillethow can I do this ?
    thanks

    I thought it worked but I guess i am stuck in with real data . Please bear with me. I have never done hierarchical queries -
    there are more ids and fields that I have to put in the condition so here are the new create/insert sample stmnts.
    drop table dummy;
    create table dummy(hdr_id number,node_id number, config_item_id number, parent_config_item_id number,ps_node_name varchar2(20));
    insert into dummy values(35981400,     21400,     24547505,     -1,     'AT2200-10H');
    insert into dummy values(35981400,     21420,     24547506,     24547505,     'AT2200-10H-UWMOD');
    insert into dummy values(35981400,     37020,     24547564,     24547506,     'Corona Treater');
    insert into dummy values(35981400,     37021,     24547565,     24547564,     'None');
    insert into dummy values(35981400,     37024,     24547566,     24547506,     'Corona Type');
    insert into dummy values(35981400,     1877321,25766779,     24547566,     'None');
    select ps_node_name name,'path' from dummy where hdr_id = 35981400
    --I have to have hdr_id=something as a condition as there are numerous rows with different ids.
    so when I query for names in one hrd_id, I should get all names in that session, with paths linking parent to child upto current level.
    expected result :
    AT2200-10H     
    AT2200-10H-UWMOD        AT2200-10H>AT2200-10H-UWMOD
    Corona Treater        AT2200-10H>AT2200-10H-UWMOD>Corona Treater
    None                        AT2200-10H>AT2200-10H-UWMOD>Corona Treater>None
    Corona Type        AT2200-10H>AT2200-10H-UWMOD>Corona Type
    None                        AT2200-10H>AT2200-10H-UWMOD>Corona Type>None
    sorry for the confusion.
    Edited by: OAF-dev on Nov 18, 2009 4:24 PM

  • Re:Query for Item and its first child Itemcode from BOM...!!!

    Dear SAP Members,
    I need a query that contains
    ItemCode,ItemDescription from oitm table and its first child item code,Item Description,Quantity,currency and price from itt1 table.I have taken all the datas but there is no ItemDescription from itt1 table.How to join all these datas.
    Please Give suggestions or query for this issue.
    With Regards,
    Revathy

    Hi try this
    Declare @BOMDetails table(TreeType Nvarchar(MAX),PItem NVARCHAR(Max),PName NVARCHAR(MAX),CItem  NVARCHAR(Max),CName NVARCHAR(MAX),Comment NVARCHAR(MAX),onHand Numeric(18,0),[Committed] Numeric(18,0),FreeStock Numeric(18,0),[Status] NVARCHAR(MAX),Quantity numeric(18,0),Price numeric(18,0),Warehouse nvarchar(MAX),Currency nvarchar(MAX))
    INSERT Into @BOMDetails
    SELECT T1.TreeType ,T0.Father AS [Parent Code], T2.ItemName AS [Parent Description], T0.Code AS [Child Code],
    T1.ItemName AS [Child Description], T0.Comment, cast((T1.OnHand ) as Numeric(18,0)) as [Un-Committed Stock],
    cast(T1.IsCommited as Numeric(18,0)) AS [Committed Stock], cast((T1.OnHand - T1.IsCommited)as Numeric(18,0)) AS [Free Stock], T2.FrgnName AS [Status],T0.Quantity,T0.Price ,T0.Warehouse,T0.Currency
    FROM ITT1 T0 INNER JOIN OITM T1 ON T0.Code = T1.ItemCode
                 INNER JOIN OITM T2 ON T0.Father = T2.ItemCode
    WHERE T0.ChildNum=1
    Union All
    SELECT ' ',T0.Father as [Parent Code], T2.ItemName AS [Parent Description], '', '', '', 0,0,0 , '',0,0,'','' FROM ITT1 T0 INNER JOIN OITM T1
    ON T0.Code = T1.ItemCode INNER JOIN OITM T2 ON T0.Father = T2.ItemCode
    Group By T0.Father,T2.ItemName
    ORDER BY T0.Father, T0.Code
    update @BOMDetails set PItem='' ,PName='' where TreeType='N' or TreeType='P'
    Select PItem as[Parent Code] ,PName as [Parent Description],CItem as [Child Code],CName as [Child Description],Comment,Quantity,Price,Warehouse,Currency   from @BOMDetails
    thanks,
    Neetu

  • MDX query for parent-child combination display

    Hi guys..
    I am really new to the Essbase technology.
    Could you please help me out with this one:
    is it possible to extract the data(for example the metadata of a outline)..eg:-
    The outline structure is as follows :
    A1
    A11
    A12
    A2
    A21
    A22
    I want a MDX query to display it as :
    A1 A11
    A1 A12
    A2 A21
    A2 A22
    I have tried various ways but couldnt come up with a query for this.
    Thanks in advance for all your help.

    Unfortunately MDX cannot do this. If you think about what you are asking for, you are essentially saying that you want to see members of the same dimension on different axis. Multi-dimensional queries can't do that (think about trying to do it with addin).
    A further limiation is that MDX is not robust enough to allow you to work the results into a single axis using a concatenation function because while there is a string-to-member function, there is no member-to-string function and concat requires a string as input.
    Other approaches would require MDX to support joins or subqueries, which it does not.
    As others have mentioned, to do what you want to do, you need outline extractor or something like that.
    *Fun fact - if you have OBIEE 11g, it can do reporting in Essbase with hierarchy members in hierarchy format or column format, which will give you the results you need.  That alone is good reason to start using OBIEE.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Hierarchy Query For Full Tree ?

    Hi Everyone,
    I want to write a hierarchy query which should give me the whole path starting from root node to each individual nodes by passing value of any individual tree member. 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(1),CHILD VARCHAR2(1) 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 'C' which gives the whole tree where the node C is present:
    A
    A->B
    A->C
    A->B->D
    A->B->E
    A->C->G
    A->B->D->F
    My Query:
    select
    sys_connect_by_path(child,'->') tree
    from
    relation
    --where (parent ='C' or child='C') 
    start with
    parent is null
    connect by
    prior child = parent
    order by tree;
    Output of my query:
    ->A
    ->A->B
    ->A->B->D
    ->A->B->D->F
    ->A->B->E
    ->A->C
    ->A->C->G
    ->H
    ->H->I
    ->H->J
    I am not able to add the condition for the query so that i can get only rows of the tree where the nod 'C' is present. i am just getting whole data from the table with all the unwanted trees.
    Can anyone please help me in getting the correct output.
    Thank you in advance.

    odie_63 wrote:
    Another solution, involving analytics : Hierarchical queries and analytic functions do not mix well together in 10g:
    SQL> select * from v$version
      2  /
    BANNER
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Prod
    PL/SQL Release 10.2.0.4.0 - Production
    CORE    10.2.0.4.0      Production
    TNS for 32-bit Windows: Version 10.2.0.4.0 - Production
    NLSRTL Version 10.2.0.4.0 - Production
    SQL> SELECT tree
      2  FROM (
      3    select sys_connect_by_path(child,'->') tree,
      4           max(case when child = 'C' then connect_by_root(child) end) over() root1,
      5           connect_by_root(child) root2
      6    from relation
      7    start with parent is null
      8    connect by prior child = parent
      9  )
    10  WHERE root1 = root2
    11  ;
      from relation
    ERROR at line 6:
    ORA-00600: internal error code, arguments: [qctcte1], [0], [], [], [], [], [], []
    SQL> Although it is much better in 11g:
    SQL> select * from v$version
      2  /
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
    PL/SQL Release 11.2.0.1.0 - Production
    CORE    11.2.0.1.0      Production
    TNS for 32-bit Windows: Version 11.2.0.1.0 - Production
    NLSRTL Version 11.2.0.1.0 - Production
    SQL> SELECT tree
      2  FROM (
      3    select sys_connect_by_path(child,'->') tree,
      4           max(case when child = 'C' then connect_by_root(child) end) over() root1,
      5           connect_by_root(child) root2
      6    from relation
      7    start with parent is null
      8    connect by prior child = parent
      9  )
    10  WHERE root1 = root2
    11  ;
    TREE
    ->A
    ->A->B
    ->A->B->D
    ->A->B->D->F
    ->A->B->E
    ->A->C
    ->A->C->G
    7 rows selected.
    SQL> SY.

Maybe you are looking for

  • How do I get rid of the "You've opened a new tab" message every time I open a new tab? It's annoying.

    Every time I open a new tab, I get the message "You've opened a new tab" How do I stop this from happening?

  • 802.1x NAC and per-user ACLs

    Can 802.1x NAC and per-user ACLs be used together on the same port? I know some of the NAC documentation says that 802.1x NAC does not support downloadable ACLs but it looks like it might be outdated and according to http://cisco.com/en/US/products/p

  • Business content activation in BI 7

    Hi - We are on BI 7 and trying to activate business content.  When I try to install an infocube with dataflow "Before and After" ie including infosource and datasources I get this message.... "On the following screen, logon with your user so that the

  • What happened to dhcp clients log?

    Not sure when but now I only have one log menu. Under advanced, Logging & SNMP,Logs and Statistics there used to be 3 log menus. Now I only have "Logs". What happened to dhcp clients? Version - 7.3.2 running DHCP(Share a public IP address) Tx

  • Reg. EDI-2-R3 IDOC integration.

    Hi,       We are going to implement a new project on EDI-2-IDOC XI integration using See burger BIC adaptor. EDI would be configured as outbound and R3 would configured as inboud. So where can I get the EDI ANSI X12 messages in .XDS format for 850, 8