To find the child sheet most to the hierarchical query

Hello
I need to findout the child sheet plus for parent to my request.
create table test_Test1 ( ID , PRNT_ID ,CHLD_ID)
 as 
 (select 1 , 10 ,20 from dual union all
 select 2 , 10 ,21 from dual union all
 select 3 , 20 ,30 from dual union all
 select 4 , 20 ,31 from dual union all
 select 5 , 30 ,40 from dual union all
 select 6 , 31 ,41 from dual union all
 select 7 , 100 ,200 from dual union all
 select 8 , 100 ,210 from dual union all
 select 9 , 200 ,300 from dual union all
 select 10 , 200 ,310 from dual union all
 select 11 , 300 ,400 from dual union all
 select 12 , 310 ,410 from dual )
Expected results
PRNT_ID   CHLD_ID
------    ------
10            21
10            40
10            41
100            210
100            400
100            410
Thank you

What:

SQL> select * from t;

        ID    PRNT_ID    CHLD_ID
---------- ---------- ----------
         1         10         20
         2         10         21
         3         20         30
         4         20         31
         5         30         40
         6         31         41
         7        100        200
         8        100        210
         9        200        300
        10        200        310
        11        300        400
        12        310        410

12 rows selected.

SQL> select min(isroot)
  2  ,      chld_id
  3  from ( select connect_by_root prnt_id  isroot
  4         ,      chld_id
  5         ,      connect_by_isleaf isleaf
  6         from   t
  7         connect by prnt_id = prior chld_id
  8       )
  9  where isleaf = 1
 10  group by chld_id;

MIN(ISROOT)    CHLD_ID
----------- ----------
         10         21
         10         40
         10         41
        100        210
        100        400
        100        410

6 rows selected.

Tags: Database

Similar Questions

  • How to convert the hierarchical query of SQL Server (CTE) to Oracle?

    How to convert the hierarchical query of SQL Server (CTE) to Oracle?

    WITH cte (col1, col2) AS
    (
    SELECT col1, col2
    FROM dbo. [tb1]
    WHERE col1 = 12
    UNION ALL
    SELECT c.col1, c.col2
    FROM dbo. [tb1] AS c INNER JOIN cte AS p ON c.col2 = p.col1
    )
    DELETE one
    FROM dbo. [tb1] AS an INNER JOIN b cte
    ON a.col1 = b.col1

    Hello
    Something like this maybe:

    DELETE FROM dbo.tb1 a
     WHERE EXISTS (
      SELECT 1
        FROM dbo.tb1 b
      WHERE a.co11 = b.col1
          AND a.col2 = b.col2
       START WITH b.col1 = 12
      CONNECT BY b.col2 = PRIOR b.col1)
    

    Although you need to do here is to check that CONNECT it BY SELECT, returns records you wait first, then the DELETION should work too.

  • How to find the sql query

    four months back someone updated my table of billing through sql developer.

    How can I find the details of the request or the original data.

    now the problem is that we rebooted the server, if it's not rest with time stamp.

    log mode is Archieve record only.
    Please help me

    I don't know why you're getting this error, I tried and it works:

    SQL> exec dbms_logmnr.add_logfile( logfilename=> 'C:\oracle\product\11.2.0\dbhome_1\RDBMS\ARC0000000736_0765299251.0001', options=> dbms_logmnr.new);
    
    PL/SQL procedure successfully completed.
    
    SQL> EXECUTE DBMS_LOGMNR.START_LOGMNR(OPTIONS => DBMS_LOGMNR.DICT_FROM_ONLINE_CATALOG);
    
    PL/SQL procedure successfully completed.
    
    SQL> exec dbms_logmnr.start_logmnr
    
    PL/SQL procedure successfully completed.
    
    SQL> select seg_owner,seg_name,sql_redo,sql_undo from v$logmnr_contents;
    
    .....
    
    35 rows selected.
    
    SQL> exec dbms_logmnr.end_logmnr
    
    PL/SQL procedure successfully completed.
    

    @Boris - you don't have to have an additional connection to the database. The thing is that if you don't have additional logging, Oracle will give you only the ROWID of the records and if it is not the same database or something has changed (as "alter table... move"), ROWID is not relevant. If you enable additional logging, you will get more information on the line (like the other columns or PK) which will help you a lot to identify RELEVANT changes. As I said, it is not mandatory, but as you say, if you want extra logging, it must be turned on BEFORE the changes in the database.

    Hope that's clear,
    Liron

  • Find the sql query in statspack report

    Salvation;
    I have 11.5.10.2 and db version 9iR2... I took a statspack report, and I should find a sql query... But admin, is kill session and I can't see complite sorted SQL query by gets for DB...

    so the question is find this query which is kiiled by admin?

    Thank you

    Hello

    Its bad news to can not find this sql... So normally it istn killed by admin, I could find it from stats$ sql_summary or v$ sql_text?

    It is possible.

    Note: 153507.1 - Applications Oracle StatsPack
    https://metalink2.Oracle.com/MetaLink/PLSQL/ml2_documents.showDocument?p_database_id=not&P_ID=153507.1

    And another question... If I have a sql printing is eating my cpu or my server resource, how do I find this sql? Under what title I can find in the statspack report

    Refer to:

    Note: 232443.1 - how to identify the resource intensive SQL for Tuning
    https://metalink2.Oracle.com/MetaLink/PLSQL/ml2_documents.showDocument?p_database_id=not&P_ID=232443.1

    Kind regards
    Hussein

  • Find the next query only job n

    Hello

    I need single query return the next workday after n days go on a date.
    Working day is every day (too much vacation) with the exception of satudarday and Sunday


    I found a few working days of request County betweeen two dates, but I can't
    to create a single query (without use of function) to add n working days, for example:

    Today is 18/04/2013, I would like to add 5 business days then

    the next working day is 25/04/2013

    If add 8 working days will be 30/04/2013

    How can he do?

    With the help of 9.2.08

    Something like...

    SQL> with t as
      2  (
      3  select to_date('18042013','ddmmyyyy') dt,
      4      8 no_of_days
      5  from dual
      6  ), t2 as
      7  (
      8  select dt,
      9     case to_char(dt,'fmday')
     10       when 'monday' then 4
     11       when 'tuesday' then 3
     12       when 'wednesday' then 2
     13       when 'thursday' then 1
     14       when 'friday' then 0
     15       when 'saturday' then -1
     16       when 'sunday' then -2
     17     end dif,no_of_days
     18  from t
     19  )
     20  select dt,no_of_days,
     21     case when no_of_days <= dif then dt+no_of_days
     22         else dt+dif+(no_of_days-greatest(dif,0))+
     23             (ceil((no_of_days-greatest(dif,0))/5)*2)
     24     end next_dt
     25  from t2;
    
    DT        NO_OF_DAYS NEXT_DT
    --------- ---------- ---------
    18-APR-13          8 30-APR-13
    

    Published by: JAC on April 18, 2013 19:17
    Not tested... It will give you a starting point, if you do not want to row generation...

  • How to find the sql query by using the hash value

    Hello

    DBVERSION: 9.2.0.8

    I generated the statspack report and I want to see total request and I hash_value here.

    in v$ sql can't see all querys... .pls suggest me other ways...

    Thank you
    Srini...

    Have you seen Peter's response? There is no installation other than that would be to store the history of the IMO. Another reason that you must pass to 10g or 11g better, now.

    Aman...

  • How to find the sql query generated by BI Publisher

    I'm looking for the physical sql query generated by BEEP when I send parameters as part of the data model.

    Of course, this can be noted in newspapers...

    Can anyone tell me the location of newspapers?

    Thanks in advance

    Have a look here http://gerardnico.com/wiki/dat/bip/log
    I explain a bit how you can get the newspaper.

    See you soon
    Nico

  • Identify the hierarchical query paths

    Hi all

    11 GR 2 DB

    create table test_h(parent varchar2(1),child varchar2(1));
    
    insert into test_h values(null,'A');
    insert into test_h values('A','B');
    insert into test_h values('B','C');
    insert into test_h values('C','D');
    insert into test_h values('B','E');
    insert into test_h values('E','F');
    insert into test_h values('','1');
    insert into test_h values('1','2');
    insert into test_h values('2','3');
    commit;
    
    SQL> select *
      2  from test_h;
    
    P C
    - -
      A
    A B
    B C
    C D
    B E
    E F
      1
    1 2
    2 3
    
    9 rows selected.
    
    SQL> select connect_by_root child root_val,child,level lvl
      2  from test_h
      3  start with parent is null
      4  connect by prior child = parent;
    
    R C        LVL
    - - ----------
    1 1          1
    1 2          2
    1 3          3
    A A          1
    A B          2
    A C          3
    A D          4
    A E          3
    A F          4
    
    9 rows selected.
    
    Expected output: An identifier for each different path
    
    R C        LVL  PATH
    - - ----------  ----
    1 1          1  PATH1
    1 2          2  PATH1  
    1 3          3  PATH1
    A A          1  PATH2
    A B          2  PATH2
    A C          3  PATH2
    A D          4  PATH2
    A E          3  PATH3
    A F          4  PATH3
    Thanks in advance

    One-way ticket (not tested... Based on the fact that hierarchical queries will produce output orderly)

    SQL> with relation as
      2  (
      3   select connect_by_root child root_val,child,level lvl,rownum rn
      4   from test_h
      5   start with parent is null
      6   connect by prior child = parent
      7  ),
      8  flag as
      9  (
     10   select root_val,child,lvl,rn,
     11          case when lvl = lag(lvl) over(order by rn)+1
     12             then 0
     13              else 1
     14          end flg
     15   from relation
     16  )
     17  select root_val,child,lvl,
     18         'PATH'||sum(flg) over(order by rn) path
     19  from flag;
    
    R C        LVL PATH
    - - ---------- --------------------------------------------------
    1 1          1 PATH1
    1 2          2 PATH1
    1 3          3 PATH1
    A A          1 PATH2
    A B          2 PATH2
    A C          3 PATH2
    A D          4 PATH2
    A E          3 PATH3
    A F          4 PATH3
    
    9 rows selected.
    
  • result of the hierarchical query in xml format

    Pls find below the example script table and the desired output format. Output XML must keep the information of hierarchy that is the requirement. Also is it possible to do it in single sql.
    Thank you.
    CREATE TABLE MAIN
    (
    IDENTIFICATION NUMBER,
    NAME VARCHAR2 (20 BYTE)
    );

    INSERT INTO THE HAND (ID, NAME) VALUES)
    1, "OS");
    INSERT INTO THE HAND (ID, NAME) VALUES)
    2, 'Windows');
    INSERT INTO THE HAND (ID, NAME) VALUES)
    3, 'BACK');
    INSERT INTO THE HAND (ID, NAME) VALUES)
    4, "1.x");
    INSERT INTO THE HAND (ID, NAME) VALUES)
    5, "1.1.x");
    INSERT INTO THE HAND (ID, NAME) VALUES)
    7, "1.1.1.1");
    INSERT INTO THE HAND (ID, NAME) VALUES)
    8, ' (1.2');
    INSERT INTO THE HAND (ID, NAME) VALUES)
    9, '2.x');
    INSERT INTO THE HAND (ID, NAME) VALUES)
    10, ' (2.1');
    INSERT INTO THE HAND (ID, NAME) VALUES)
    11, "2.2");
    INSERT INTO THE HAND (ID, NAME) VALUES)
    12, ' 2.2.1');
    INSERT INTO THE HAND (ID, NAME) VALUES)
    13, ' 2.2.2');
    COMMIT;

    CREATE TABLE RELA
    (
    NUMBER OF REL_ID
    IDENTIFICATION NUMBER,
    NUMBER OF PARENT_REL_ID
    );

    INSERT INTO RELA (REL_ID, ID, PARENT_REL_ID) VALUES)
    1, 1, NULL);
    INSERT INTO RELA (REL_ID, ID, PARENT_REL_ID) VALUES)
    2, 2, 1);
    INSERT INTO RELA (REL_ID, ID, PARENT_REL_ID) VALUES)
    3, 4, 2);
    INSERT INTO RELA (REL_ID, ID, PARENT_REL_ID) VALUES)
    4, 5, 3);
    INSERT INTO RELA (REL_ID, ID, PARENT_REL_ID) VALUES)
    5, 7, 4);
    INSERT INTO RELA (REL_ID, ID, PARENT_REL_ID) VALUES)
    6, 8, 4);
    INSERT INTO RELA (REL_ID, ID, PARENT_REL_ID) VALUES)
    7, 9, 2);
    INSERT INTO RELA (REL_ID, ID, PARENT_REL_ID) VALUES)
    8, 10, 7);
    INSERT INTO RELA (REL_ID, ID, PARENT_REL_ID) VALUES)
    12, 7, 11);
    INSERT INTO RELA (REL_ID, ID, PARENT_REL_ID) VALUES)
    14, 9, 9);
    INSERT INTO RELA (REL_ID, ID, PARENT_REL_ID) VALUES)
    15, 10, 14);
    INSERT INTO RELA (REL_ID, ID, PARENT_REL_ID) VALUES)
    9, 3, 1);
    INSERT INTO RELA (REL_ID, ID, PARENT_REL_ID) VALUES)
    10, 4, 9);
    INSERT INTO RELA (REL_ID, ID, PARENT_REL_ID) VALUES)
    11, 5, 10);
    INSERT INTO RELA (REL_ID, ID, PARENT_REL_ID) VALUES)
    16, 11, 14);
    INSERT INTO RELA (REL_ID, ID, PARENT_REL_ID) VALUES)
    13, 8, 10);
    INSERT INTO RELA (REL_ID, ID, PARENT_REL_ID) VALUES)
    17, 12, 16);
    INSERT INTO RELA (REL_ID, ID, PARENT_REL_ID) VALUES)
    18, 13, 16);
    COMMIT;

    Example query
    Select rel_id, level, lpad (' ', 5 * level) | name,
    XmlElement ("rel_id", XMLAttributes (name as "name", rel_id as "rel_id")) as val
    principal, rela
    where main.id = rela.id
    Start with parent_rel_id is null
    Connect prior rel_id = parent_rel_id;

    Required xml output
    Required xml output

    < 1 name = "OS" >
    < name 2 = "Windows" >
    < 3 name = "1.x" 3 > ""
    < name 4 = "1.1.x" >
    < name 5 = "1.1.1.1" > < / 5 >
    < name 6 = "1.2" > < / 6 >
    < / 4 >
    < / 3 >
    < name = "" 2.x 7 ">"
    < name 8 = "2.1" > < / 8 >
    < / 7 >
    < / 2 >
    < name 9 'BACK' = >
    < name = "2.x 14" > "
    < name 15 = "2.1" > < / 15 >
    < name 16 = "2.2" >
    < name 17 = '2.2.1' > < / 17 >
    < name 18 = '2.2.2' > < / 18 >
    < / 16 >
    < / 14 >
    < 10 name = "1.x" > "
    < name 11 = "1.1.x" >
    < name 12 = "1.1.1.1" > < / 12 >
    < / 11 >
    < name 13 = "1.2" >
    < / 13 >
    < / 10 >
    < / 9 >
    < 1 >

    Published by: delights on September 18, 2009 16:47

    Published by: delights Sep 19, 2009 09:53

    No string function helps eliminate r because the xml output is great (in a real scenario) which gives "buffer too small" error.

    Try sth like

    SQL>select replace(x.column_value.getclobval(), 'XXX') xml
      2    from xmltable ('.' passing dbms_xmlgen.getxmltype (dbms_xmlgen.
      3                   newcontextfromhierarchy (
      4                   'select level, xmlelement (evalname ''XXX'' || rel_id, xmlattributes(name "name")) name
      5        from main, rela
      6       where main.id = rela.id
      7  start with parent_rel_id is null
      8  connect by prior rel_id = parent_rel_id'
      9                   ))) x
     10  /
    
    XML
    --------------------------------------------------------------------------------
    
    <1 name="OS">
      <2 name="Windows">
        <3 name="1.x">
          <4 name="1.1.x">
            <5 name="1.1.1.1"/>
            <6 name="1.2"/>
          
        
        <7 name="2.x">
          <8 name="2.1"/>
        
      
      <9 name="DOS">
        <10 name="1.x">
          <11 name="1.1.x">
            <12 name="1.1.1.1"/>
          
          <13 name="1.2"/>
        
        <14 name="2.x">
          <15 name="2.1"/>
          <16 name="2.2">
            <17 name="2.2.1"/>
            <18 name="2.2.2"/>
          
        
      
    
    
    SQL>
    

    Newcontextfromhierarchy is not a documented feature do not know if it will issue in releated support this in production code.

    Oracle's recommeds to use newcontextfromhierarchy in Metalink Note 882887.1 ;)

  • To find the Top most parent SQL

    How to find the top most parent SQL. I want to avoid the hierarchical query that shows a high cost to run. Please suggest alternative options to find the parent

    Maybe (when having multiple hierarchy trees) to be adapted to your needs

    Select empno, I

    from (select empno, I

    WCP

    where empno = 7876

    model

    hierarchy of reference on (select employee empno,

    Manager Mgr

    WCP

    )

    dimension (employee)

    measures (Manager)

    main main_model

    size of (0 I)

    measures (empno)

    rules iterate (100) until (empno [iteration_number + 1] is null)

    (

    EmpNo [iteration_number + 1] = hierarchy.manager [empno [iteration_number]]

    )

    )

    where empno is not null

    order by I desc

    EMPNO I
    7839 3
    7566 2
    7788 1
    7876 0

    Concerning

    Etbin

  • Where to find the request resolved, sent to the database?

    Version 4.1.1.00.23

    Hello

    Where and how can I find the actual query that is sent to the database?  I enabled debugging in the Dev toolbar, but I still don't see where is the query that is sent to the database? I'm hoping to see a view with the elements of page not resolved not what's actually in the page.

    I have a query on a collection and I get an error "command not properly ended SQL" and I do not see why it is not "properly completed".

    Hope this is clear.

    Let me know if not.

    Thank you

    Joe

    Mike,

    I got it to work!

    In the query for the Collection, I went back to using the function replace to replace the colon with a comma and where clause of the query for the page I used the get_list function.

    So in the Collection query, she went from:

    AND (tbs_team_id IN (SELECT tbs_team_id FROM tbs_forecast_year get_list('|| :F189_TEAM_ID ||')) OR 0 IN (SELECT tbs_team_id FROM tbs_forecast_year get_list('|| :F189_TEAM_ID ||')))
    

    To do this:

    AND (tbs_team_id IN ('||replace(:F189_TEAM_ID,':', ',')||') OR 0 IN ('||replace(:F189_TEAM_ID,':', ',')||'))
    

    And in the query to create the page, I put this:

    AND (c002 IN (SELECT * FROM TABLE(get_list(:P11_TEAM))) OR 0 IN (SELECT * FROM TABLE(get_list(:P11_TEAM))))
    

    And fixed it.

    Thanks Tony and Ingenio VERY much for your help!

    Thank you

    Joe

  • generations of months using the sql query

    Hello

    Based on the input of date parameter, I need display every month in the current year and last year.

    For example, suppose that my setting date is December 5, 14 ', I need the output below.

    JANUARY

    FEBRUARY

    MARCH

    APRIL

    MAY

    JUNE

    JULY

    AUGUST

    SEPTEMBER

    OCTOBER

    NOVEMBER

    DECEMBER

    JANUARY

    FEBRUARY

    MARCH

    APRIL

    PEUT

    Until the month of May and the month last year. I came with the request. Please find the following query.

    Select to_char (add_months (trunc(sysdate,'year'), level-1), 'MONTH') mth

    of the double

    connect by level < = 12

    Union of all the

    Select to_char (to_date (ddate, 'MM'), 'MONTH') month

    (select 1 + rownum - 1 ddate

    from user_objects

    where (1 + rownum - 1) < = to_number (to_char (to_date ('12-05-14', ' dd-mm-yy'), 'mm')));

    But I don't want to use the data user_objects dictionary. Can you please guide how to achieve this output, or can u give me some other request too if possible.

    Thank you

    Siva

    Try the below

    SELECT TO_CHAR (ADD_MONTHS (ADD_MONTHS (TRUNC (TO_DATE(:date1,'DD-MM-YY'), 'MM'),

    ((- MONTHS_BETWEEN (trunc (to_date(:date1,'DD-mm-YY'), 'MM'), trunc (to_date(:date1,'DD-mm-YY'), 'YY')) + 12)).

    (LEVEL-1))

    , 'MONTHS '.

    'NLS_DATE_LANGUAGE = ENGLISH') FROM dual months_between

    CONNECT BY LEVEL<=>

  • Need to rotate the sub query using 11 g

    Hello

    Please find the below query

    SELECT AGING_BUCKET_ID, DAYS_START, DAYS_TO, AR_AGING_BUCKET_LINES TYPE
    WHERE AGING_BUCKET_ID = 3

    It displays the data as below

    AGING_BUCKET_ID DAYS_START DAYS_TO TYPE

    3-9999 0 CURRENT
    3 1 30 LAST
    3 31 60 LAST
    3 61 90 LAST
    3 91 9999999 PAST


    I tried to rotate the data, tried to make use of the PIVOT of the 11 g used the following query function

    WITH AGBUCK AS
    (
    SELECT AGING_BUCKET_ID, DAYS_START, DAYS_TO, AR_AGING_BUCKET_LINES TYPE
    WHERE AGING_BUCKET_ID = 3
    ) SELECT * FROM AGBUCK
    PIVOT)
    DAYS_START s1, s2 DAYS_TO, type
    FOR AGING_BUCKET_ID
    (3)
    );

    finished in the msg below:-ora-56902: wait for the aggregate within the operation of pivot function

    can you please help me to fix it.

    Concerning
    Yram

    Hi, Yram,

    Whenever you have a problem, after a few sample data and outcomes from these data.
    Sorry, I can't make a good guess at what you want, and I'm not an Oracle 11 database now to test. I think you want something like this:

    WITH      AGBUCK      AS
    (
         SELECT      AGING_BUCKET_ID
         ,     DAYS_START
         ,     DAYS_TO || TYPE      AS label
         FROM      AR_AGING_BUCKET_LINES
         WHERE      AGING_BUCKET_ID     = 3
    )
    SELECT     *
    FROM     agbuck
    PIVOT     (     MIN (days_start)
         FOR     label
         IN     (     '0 CURRENT'     AS current_0
              ,     '30 PAST'     AS past_30
              ,     '60 PAST'     AS past_60
              ,     '90 PAST'     AS past_90
              ,     '9999999 PAST'     AS past_9999999
              )
         )
    ;
    

    The first thing inside the parentheses after the PIVOT keyword must be an aggregate function. If there is a one-to-one correspondence between the lines in the "input" table and cells in the output, so no matter if you use the MIN or MAX (or, in the case of numbers, AVG or SUM).

  • hierarchical query of VO in the ofa page

    Hello

    I try to use the hierarchical query in VO for the display of all levels of supervisors for employee and want to display in populist:

    This is the query

    REPLACE SELECT distinct (mgx.full_name, "',' ') supervisor_full_name;

    XPP. Employee_number

    OF per_assignments_x pax,.

    per_people_x ppx,

    per_people_x mgx,

    per_positions pp,

    per_jobs pj,

    per_position_definitions ppd

    WHERE ppx.person_id = pax.person_id

    AND ppx.current_employee_flag = 'Y '.

    AND mgx.person_id = pax.supervisor_id

    AND pp.position_id = pax.position_id

    AND pj.job_id = pax.job_id

    AND ppd.position_definition_id = pp.position_definition_id

    START WITH ppx.employee_number =: 1

    CONNECT BY PRIOR MGX.employee_number = ppx.employee_number AND LEVEL < 6

    I'm trying to get this VO implemented PR when I run the page in jdeveloper with parameter binding, it's getting error.

    oracle.apps.fnd.framework.OAException: oracle.jbo.SQLStmtException: 27122 Houston: SQL error in the preparation of the statement.

    I would like to delete the parameter binding and executing CO VO past these two statements may be:

    START WITH ppx.employee_number =: 1

    CONNECT BY PRIOR MGX.employee_number = ppx.employee_number AND LEVEL < 6

    How can I do?

    Thank you

    MK

    has worked?

  • Find the parent of a child

    Hi all

    I have the following problem, I have a table with the following data

    Parent child
    101 201
    102 202
    201 301
    202 302
    301 401
    301 403

    Now I need to write a select query to find the top most parent of the given child, that is to say that I gave my input like 201 302 and 403 so my output should be

    Parent child
    101 201-> (201 is the son of 101)
    102 302-> (302 is the child of 202, 202 is the child of 102)
    101 403-> (403 is the child of 301, 301 - > 201, 201-> 101)

    Thanks for your help,
    REDA

    Hi, Raj,

    Welcome to the forum!

    Whenever you have any questions, post your examples of data in a form that people can use to recreate the problem and test their solutions.
    For example:

    CREATE TABLE     table_x
    (       parent     NUMBER (4)
    ,     child     NUMBER (4)     PRIMARY KEY
    );
    
    INSERT INTO table_x (parent, child) VALUES (101, 201);
    INSERT INTO table_x (parent, child) VALUES (102, 202);
    INSERT INTO table_x (parent, child) VALUES (201, 301);
    INSERT INTO table_x (parent, child) VALUES (202, 302);
    INSERT INTO table_x (parent, child) VALUES (301, 401);
    INSERT INTO table_x (parent, child) VALUES (301, 403);
    COMMIT;
    

    A WITH clause that, as Whithat posted, is also good.

    Always tell what version of Oracle you are using. This is particularly important with parent-child problems, because each version since Oracle 7 has had significant changes in this area. The following query will work in Oracle 10 (and more).

    SELECT      parent
    ,      CONNECT_BY_ROOT child     AS child
    FROM      table_x
    WHERE      CONNECT_BY_ISLEAF     = 1
    START WITH     child     IN (201, 302, 403)
    CONNECT BY     child     = PRIOR parent
    ;
    

    If you have Oracle 9, then you cannot use CONNECT_BY_ROOT, but you can get the same information from SYS_CONNECT_BY_PATH.

    The output of this product, in light of the data from the example above, is:

    `   PARENT      CHILD
    ---------- ----------
           101        201
           102        302
           101        403
    

    I guess that's what you wanted, and that the other things you posted your results (such as "---> (201 is the son of 101)"), just explained.
    The explanation is very useful, but clearly what you want really to the exit, and what is just your comments.

Maybe you are looking for

  • Can I use my time capsule for wired Internet?

    The fundamental question is, I can connect my time capsule to my wireless internet router and then use the capsule to connect my iMac to the Internet with an Ethernet cable? The back story: I have an i7 iMac late 2009 that has worked perfectly until

  • It's never going to be Thunderbird for Android?

    He is developing, or are we just not worry?

  • restore the windows available

    I went to one of my FCPX library and deleted some files. Also, I took all my FCPX libraries and place them in a folder. Something tells me that it is a 'no-no' because after my FCPX started acting weird. Then when you restart my FCPX he stuck to "res

  • Can't find Sticky Notes!

    Can't get Sticky Notes under accessories in the start menu. Recently, I ran a software shortcut Fixer and I think that he got rid of sticky notes. What can I do to get it back?

  • How to implement a stack of screen "single instance".

    I'm looking to implement an application that accepts only a single instance of specific screens.  What is the best way to achieve this?  I have checked the documentation and can't seem to find anything that addresses this issue. The idea is similar t