Hierarchical query to retrieve child.. sub-child .. so on

Please help me writing a SQL Query to fetch all child tables and sub-children and so on for a given table in the following manner:
TABLE_NAME LEVEL
A 1
AA 2
AAA 3
AB 2
ABA 3
ABB 3
B 1
BA 2
BB 2
I have written a query to give only the first level children.
SELECT DISTINCT b.table_name, 1 level_no
FROM user_constraints a, user_constraints b
WHERE a.constraint_name = b.r_constraint_name
AND a.table_name = :table_name;

You can find multiple examples on http://asktom.oracle.com
Ex.: http://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:426166454665#9313682577033

Similar Messages

  • Retrieve Parent Child Sub-Child recors in SQL Query

    I've a self reference table and it has Parent-Child-Subchild relation. I'm getting an output (from second answer http://stackoverflow.com/questions/16031000/get-records-containing-all-the-child-records-in-sql-server) as expected, but it's
    displaying results in below format.
    <parent id> - <name> - <code>
    <child id> - <name> - <code>
    <child id> - <name> - <code>
    <child id> - <name> - <code>
    <child id> - <name> - <code>
    <sub child id> - <name> - <code>
    <sub child id> - <name> - <code>
    <sub child id> - <name> - <code>
    I want to display the results like in below format with applying some indent style to distinguish parent\ child\sub-child relationship.
    <parent id> - <name> - <code>
    <child id> - <name> - <code>
    <child id> - <name> - <code>
    <sub child id> - <name> - <code>
    <sub child id> - <name> - <code>
    <child id> - <name> - <code>
    <child id> - <name> - <code>
    <sub child id> - <label> - <code>
    <child id> - <name> - <code>
    <child id> - <name> - <code>
    Please assist me on foumulating results as expected.

    BOL has a good example of doing this in the CTE topic.  See http://technet.microsoft.com/en-us/library/ms175972%28v=sql.105%29.aspx Here is a slightly modified
    version of what is in BOL.
    CREATE TABLE #MyEmployees
    EmployeeID smallint NOT NULL,
    FirstName nvarchar(30) NOT NULL,
    LastName nvarchar(40) NOT NULL,
    Title nvarchar(50) NOT NULL,
    DeptID smallint NOT NULL,
    ManagerID int NULL,
    CONSTRAINT PK_EmployeeID PRIMARY KEY CLUSTERED (EmployeeID ASC)
    -- Populate the table with values.
    INSERT INTO #MyEmployees VALUES
    (1, N'Ken', N'Sánchez', N'Chief Executive Officer',16,NULL)
    ,(273, N'Brian', N'Welcker', N'Vice President of Sales',3,1)
    ,(274, N'Stephen', N'Jiang', N'North American Sales Manager',3,273)
    ,(275, N'Michael', N'Blythe', N'Sales Representative',3,274)
    ,(276, N'Linda', N'Mitchell', N'Sales Representative',3,274)
    ,(285, N'Syed', N'Abbas', N'Pacific Sales Manager',3,273)
    ,(286, N'Lynn', N'Tsoflias', N'Sales Representative',3,285)
    ,(16, N'David',N'Bradley', N'Marketing Manager', 4, 273)
    ,(23, N'Mary', N'Gibson', N'Marketing Specialist', 4, 16);
    ; WITH DirectReports(Name, Title, EmployeeID, EmployeeLevel, Sort)
    AS (SELECT CONVERT(varchar(255), e.FirstName + ' ' + e.LastName),
    e.Title,
    e.EmployeeID,
    1,
    CONVERT(varchar(255), e.FirstName + ' ' + e.LastName)
    FROM #MyEmployees AS e
    WHERE e.ManagerID IS NULL
    UNION ALL
    SELECT CONVERT(varchar(255), REPLICATE (' ' , EmployeeLevel) +
    e.FirstName + ' ' + e.LastName),
    e.Title,
    e.EmployeeID,
    EmployeeLevel + 1,
    CONVERT (varchar(255), RTRIM(Sort) + '| ' + FirstName + ' ' +
    LastName)
    FROM #MyEmployees AS e
    JOIN DirectReports AS d ON e.ManagerID = d.EmployeeID
    SELECT EmployeeID, Name, Title, EmployeeLevel
    FROM DirectReports
    ORDER BY Sort;
    GO
    drop table #MyEmployees;
    Tom

  • No parent without child (hierarchical query)

    Dear Gurus,
    I have a problem with Hierarchical query. That is, I want show only those PARENTS who have child.
    Table structure:
    Business Unit
    BU_NO     BU_NAME BU_NO_PARENT
    1 Marketing
    2 Research 1
    3 Planning 1
    4 Strategic 3
    5 Admin
    6 Human Resources 5
    7 Accounts 5
    Employee
    EMP_NO     ENAME BU_NO
    7369 SMITH 2
    7499 ALLEN 6
    7521 WARD 1
    7566 CLARK 5
    7654 MARTIN 7
    7698 BLAKE 2
    7788 SCOTT 7
    7839 KING 5
    I have to show the list of employees with BU. But exclude those BU which have no employee. My output should be like this:
    NAME
    Marketing
    -----WARD
    -----Research
    ----------SMITH
    Admin
    -----CLARK
    -----KING
    -----Human Resources
    ----------ALLEN
    -----Accounts
    ----------MARTIN
    ----------SCOTT
    For this I've written a query but it shows all BUs (with employee and without employee)
    Query is:
    SELECT LPAD(obj_name, LENGTH(obj_name)+(LEVEL-1)*5, '-') obj_name
    FROM
    (SELECT 'B'||bu_no obj_no, bu_name obj_name, 'B'||bu_no_parent parent_obj_no FROM hr_bu
    UNION ALL
    SELECT TO_CHAR(emp_no), ename, 'B'||bu_no FROM hr_emp)
    START WITH parent_obj_no = 'B'
    CONNECT BY PRIOR obj_no = parent_obj_no;
    Can you please help me in writing query to eliminate BU from output where no employee is working.
    Thanks.

    Hi,
    To exclude certain nodes without excluding their descendants, simply use a WHERE-Clause, like this:
    SELECT     LPAD     ( obj_name
              , LENGTH (obj_name) + (LEVEL-1) * 5
              ) obj_name
    FROM     (
         SELECT     'B' || bu_no          obj_no
         ,     bu_name           obj_name
         ,     'B' || bu_no_parent     parent_obj_no
         FROM     hr_bu
         UNION ALL
         SELECT     TO_CHAR (emp_no)
         ,     ename
         ,     'B' || bu_no
         FROM     hr_emp
         ) u
    WHERE     obj_no     NOT LIKE 'B%'
    OR     EXISTS     (     -- Begin correalated sub-query to find emps in this bu
              SELECT     0
              FROM     hr_emp
              WHERE     'B' || bu_no     = u.obj_no
              )     -- End correalated sub-query to find emps in this bu
    START WITH     parent_obj_no     = 'B'
    CONNECT BY     PRIOR obj_no     = parent_obj_no;Output:
    OBJ_NAME
    Marketing
    -----Research
    ----------SMITH
    ----------BLAKE
    -----WARD
    Admin
    -----Human Resources
    ----------ALLEN
    -----Accounts
    ----------MARTIN
    ----------SCOTT
    -----CLARK
    -----KINGThe results above include employee Blake, who was not included in your sample output, but I assume he was left off by mistake.
    The solution above may produce misleading output. For example, if you remove employee Ward from your sample data, then the Marketing unit will not appear, but the Research unit will still appear (as you want), but Reasearch will be at LEVEL=2, so you may get the output below, which seems to indicate that Research is a child of Admin:
    OBJ_NAME
    Admin
    -----Human Resources
    ----------ALLEN
    -----Accounts
    ----------MARTIN
    ----------SCOTT
    -----CLARK
    -----KING
    -----Research
    ----------SMITH
    ----------BLAKETo avoid this kind of confusion, I would display SYS_CONNECT_BY_PATH (obj_name) rather than obj_name, or I would include all Business Units that were ancestors of Business units that have employees.

  • Query Help with Parent, Child, Child's Child

    Hi all,
    Need some help with a query.  I'm trying to create a stored procedure that is sort of like a Customer, Order, Order, Details.  In my situation the tables are different but nevertheless, I want to grab all the fields from the  Parent, Child,
    and Childs' Child, where the Parent.ParentID = @Parameter.  I tried this:
    CREATE PROCEDURE [dbo].[spGetCompleteProjectXML]
    @ProjectID int = 0
    AS
    SELECT *,
    (SELECT *,
    (SELECT *
    FROM PageControls
    WHERE (PageControls.ProjectPageID = ProjectPages.ProjectPageID))
    FROM ProjectPages
    WHERE (ProjectPages.ProjectID = @ProjectID))
    FROM Projects
    WHERE (ProjectID = @ProjectID)
    FOR XML AUTO, ELEMENTS
    RETURN 0
    I think I'm close, but it was my best effort.  Could someone help?
    thanks in advance

    Hi TPolo,
    Regarding your description, are you looking for a sample like below?
    CREATE TABLE customer(customerID INT, name VARCHAR(99))
    INSERT INTO customer VALUES(1,'Eric')
    INSERT INTO customer VALUES(2,'Nelson')
    CREATE TABLE orders(orderID INT,customerID INT)
    INSERT INTO orders VALUES(1,1);
    INSERT INTO orders VALUES(2,1)
    INSERT INTO orders VALUES(3,2)
    INSERT INTO orders VALUES(4,2)
    CREATE TABLE orderDetails(orderID INT,item VARCHAR(99))
    INSERT INTO orderDetails VALUES(1,'APPLE1')
    INSERT INTO orderDetails VALUES(1,'BANANA1')
    INSERT INTO orderDetails VALUES(2,'APPLE2')
    INSERT INTO orderDetails VALUES(2,'BANANA2')
    INSERT INTO orderDetails VALUES(3,'APPLE3')
    INSERT INTO orderDetails VALUES(3,'BANANA3')
    INSERT INTO orderDetails VALUES(4,'APPLE4')
    INSERT INTO orderDetails VALUES(4,'BANANA5')
    SELECT customer.customerID,customer.name,
    (SELECT orderId,
    SELECT item FROM orderDetails WHERE orderID=orders.orderID FOR XML AUTO,TYPE,ELEMENTS
    FROM orders Where customerID=customer.customerID FOR XML AUTO,TYPE,ELEMENTS)
    FROM customer WHERE customerID=1
    FOR XML AUTO,ELEMENTS
    DROP TABLE customer,orderDetails,orders
    If you have any feedback on our support, please click
    here.
    Eric Zhang
    TechNet Community Support

  • How to get the parent window in sub-child controller class in javafx?

    how to get the parent window in sub-child controller class in javafx?

    You can get the window in which a node is contained with
    Window window = node.getScene().getWindow();Depending when this is invoked, you might want to check the Scene is not null before calling getWindow().
    If the window is a stage that is owned by another window, you can get the "parent" or "owner" window with
    Window owner = null ;
    if (window instanceof Stage) {
      Stage stage = (Stage) window ;
      owner = stage.getOwner();
    }

  • Query to fetch child of child records of a given party

    Hi,
    We have requirement to fetch the child records(child of child records also) of a given party name.
    We had written the below query:
    SELECT distinct hp.party_name
    FROM hz_parties hp,
    hz_relationships hzr,
    hz_parties hp2
    WHERE hzr.direction_code = 'C'
    AND hp.party_id = hzr.subject_id
    AND hzr.object_id = hp2.party_id
    AND relationship_type ='Parent-Child Hierarchy'
    --'Org Structure'
    --'Parent-Child Hierarchy'
    AND hz_utility_v2pub.get_lookupmeaning
    ('AR_LOOKUPS',
    'PARTY_RELATIONS_TYPE',
    hzr.relationship_code
    ) = 'Child of'
    AND hp2.party_name = :P_CUSTOMER
    This query fetches only one level of parent and child records.
    Please help us in fetching the child of child records also. We tried using 'Connect By', but its not working as expected.
    Thanks in advance.

    Hi,
    We have requirement to fetch the child records(child of child records also) of a given party name.
    We had written the below query:
    SELECT distinct hp.party_name
    FROM hz_parties hp,
    hz_relationships hzr,
    hz_parties hp2
    WHERE hzr.direction_code = 'C'
    AND hp.party_id = hzr.subject_id
    AND hzr.object_id = hp2.party_id
    AND relationship_type ='Parent-Child Hierarchy'
    --'Org Structure'
    --'Parent-Child Hierarchy'
    AND hz_utility_v2pub.get_lookupmeaning
    ('AR_LOOKUPS',
    'PARTY_RELATIONS_TYPE',
    hzr.relationship_code
    ) = 'Child of'
    AND hp2.party_name = :P_CUSTOMER
    This query fetches only one level of parent and child records.
    Please help us in fetching the child of child records also. We tried using 'Connect By', but its not working as expected.
    Thanks in advance.

  • Need query to get parent and child relations

    Hi,
    SELECT
    a.ID MASTER_ID, a.UNIQUE_NAME MASTER_UNIQUE_NAME, d.ID CHILD_ID, d.UNIQUE_NAME CHILD_UNIQUE_NAME, 1 SUB_LEVEL
    FROM
    srm_projects a,
    prTask b,
    prSubProject c,
    srm_projects d
    WHERE
    a.id = b.prProjectID
    AND b.prID = c.prTaskID
    AND c.PRREFPROJECTID=d.id
    The above query gives a project and its child.
    Child project can inturn have child projects.
    But the above query gives only the first level.
    To obtain second level I am presently using the following query
    SELECT
    a.ID MASTER_ID, a.UNIQUE_NAME MASTER_UNIQUE_NAME, d.ID CHILD_ID, d.UNIQUE_NAME CHILD_UNIQUE_NAME, 1 SUB_LEVEL
    FROM
    srm_projects a,
    prTask b,
    prSubProject c,
    srm_projects d
    WHERE
    a.id = b.prProjectID
    AND b.prID = c.prTaskID
    AND c.PRREFPROJECTID=d.id
    UNION ALL
    SELECT
    a.ID, a.UNIQUE_NAME, g.ID, g.UNIQUE_NAME, 2 SUB_LEVEL
    FROM
    srm_projects a,
    prTask b,
    prSubProject c,
    srm_projects d,
    prSubProject e,
    prTask f,
    srm_projects g
    WHERE
    a.id = b.prProjectID
    AND b.prID = c.prTaskID
    AND c.PRREFPROJECTID=d.id
    AND d.ID = f.PRPROJECTID
    AND f.prID = e.prTaskID
    AND e.PRREFPROJECTID=g.id
    But the problem is there is no limit on levels. They can go on to 20 to 30.
    So i need a query which gives me all the levels and not as above one where i am specifying till wht level.
    Please guide me.

    Thanks.
    Please find the table structures
    CREATE TABLE SRM_PROJECTS
    ID NUMBER NOT NULL,
    NAME VARCHAR2(240 BYTE),
    UNIQUE_NAME VARCHAR2(60 BYTE),
    DESCRIPTION VARCHAR2(2286 BYTE),
    IS_ACTIVE NUMBER DEFAULT 1 NOT NULL,
    CREATED_DATE DATE NOT NULL,
    CREATED_BY NUMBER NOT NULL,
    LAST_UPDATED_DATE DATE NOT NULL,
    LAST_UPDATED_BY NUMBER NOT NULL,
    CREATE TABLE PRTASK
    PRUID VARCHAR2(32 BYTE),
    PRID NUMBER(10),
    PRPROJECTID NUMBER(10),
    PRISUNPLANNED NUMBER(10) DEFAULT 0 NOT NULL,
    PRSHORTNAME VARCHAR2(48 BYTE),
    PRNAME VARCHAR2(450 BYTE),
    PREXTERNALID VARCHAR2(48 BYTE),
    PRISMILESTONE NUMBER(10) DEFAULT 0 NOT NULL,
    PRCATEGORY VARCHAR2(96 BYTE),
    CREATE TABLE PRSUBPROJECT
    PRUID VARCHAR2(32 BYTE),
    PRID NUMBER(10),
    PRTASKID NUMBER(10),
    PRREFPROJECTID NUMBER(10),
    PRREFTASKID NUMBER(10),
    PRISREADONLY NUMBER(10) DEFAULT 0 NOT NULL,
    PRISIPD NUMBER(10) DEFAULT 0 NOT NULL,
    PRMODBY VARCHAR2(96 BYTE),
    PRMODTIME DATE
    )

  • [Oracle 8i] Need help pruning branches from a hierarchical query

    My problem is that my hierarchical query seems only to trim out the values that don't meet my criteria, but still includes their children. When my query hits a record that does not meet my criteria, I want it to stop there. I've tried including the criteria in just the 'where' clause of the query, and have also put the criteria in the 'connect by' clause as well, but nothing has fixed it. Please keep in mind I'm using Oracle 8i, so I can't use some of the 'nicer' statements for hierarchical queries that they introduced in 9. I'm stuck with 'Start With...Connect By'.
    I have sample tables/data that I can post if someone needs to see that to help me, but to start with, here's my current query:
    SELECT     *
    FROM     (
              SELECT
                   LEVEL
              ,     c_bill.comp_part_nbr                     AS     c_part_nbr
              ,     (select c_part.part_desc
                   FROM part c_part
                   WHERE c_part.part_nbr=c_bill.comp_part_nbr)     AS     c_part_desc
              ,     (SELECT c_part.part_type
                   FROM part c_part
                   WHERE c_part.part_nbr=c_bill.comp_part_nbr)      AS     c_part_type
              ,     c_bill.qty_per                          AS     c_qty_per_p
              ,     c_bill.qty_per_type                     AS     c_qty_per_type
              ,     (SELECT c_part.qty_on_hand                
                   FROM part c_part
                   WHERE c_part.part_nbr=c_bill.comp_part_nbr)      AS     c_qty_on_hand
              ,     c_bill.oper_nbr                     AS     rqd_at_op
              ,     c_bill.comp_off_adj                     AS     rqd_offset
              ,     c_bill.bom_doc_nbr                     AS     p_part_nbr
              ,     (SELECT p_part.qty_on_hand
                   FROM part p_part
                   WHERE p_part.part_nbr=c_bill.bom_doc_nbr)      AS     p_qty_on_hand
              FROM
                   BILL c_bill
              WHERE
                             (c_bill.status           =      'RL')           
                        AND     (c_bill.view_code     IN      ('M','G'))     
                        AND     (c_bill.end_eff_dt     >      SYSDATE)      
                        AND     (c_bill.begn_eff_dt     <=      SYSDATE)
              START WITH c_bill.bom_doc_nbr=RPAD(?,25)
              CONNECT BY PRIOR c_bill.comp_part_nbr=c_bill.bom_doc_nbr
              AND     c_bill.view_code     IN     ('M','G')     
              AND     c_bill.status          =     'RL'
              AND      c_bill.end_eff_dt     >     SYSDATE
              AND     c_bill.begn_eff_dt     <=     SYSDATE     
         ) a
    WHERE     c_part_type = 'M'

    The outside criterion of part_type='M' isn't my problem. Where I'm actually seeing my issue rear its ugly head is in the criterion:
    (c_bill.view_code     IN      ('M','G'))What I'll have happen is that one of the children or grandchildren of the part number I'm querying for (my parameter), will be of some view code that's not 'M' or 'G'. In my sample data below, I have a level 4 part that is part of the 'H' view code, which I don't want, nor do I want it's children. However, its child is in the 'G' view code, and my query returns it anyway.
    In my sample data below, I'm assuming that the parameter = 'XYZ-100'
    CREATE TABLE part
    part_nbr     varchar(25) not null,
    part_desc     varchar(25) not null,
    part_type     char(1) not null,
    qty_on_hand     double(13,4) not null
    CONSTRAINT part_pk
    PRIMARY KEY (part_nbr),
    CONSTRAINT check_part_type
    CHECK (part_type IN ('M','P','X','Y')),
    CONSTRAINT check_qty_on_hand
    CHECK (qty_on_hand >= 0)
    CREATE TABLE bill
    row_added_ts     char(20) not null,
    bom_doc_nbr     varchar(25) not null,
    comp_part_nbr     varchar(25) not null,
    qty_per          double(9,5) not null,
    qty_per_type     char(1) not null,
    oper_nbr     char(4) not null,
    comp_off_adj     double(3,0),
    status          char(2),
    view_code     char(1) not null,
    end_eff_dt     date() not null,
    begn_eff_dt     date() not null
    CONSTRAINT bill_pk
    PRIMARY KEY (row_added_ts),
    CONSTRAINT check_qty_per_type
    CHECK (qty_per_type IN ('0','1','2','3')),
    CONSTRAINT check_status
    CHECK (status IN ('IN', 'RL')),
    );     Values for those tables:
    INSERT INTO part
    VALUES ('xyz-1', 'purchased part', 'P', 5);
    INSERT INTO part
    VALUES ('xyz-2', 'purchased part', 'P', 1);
    INSERT INTO part
    VALUES ('xyz-3', 'purchased part', 'P', 1);
    INSERT INTO part
    VALUES ('xyz-3a', 'manufactured part', 'M', 1);
    INSERT INTO part
    VALUES ('xyz-4', 'purchased part', 'P', 1);
    INSERT INTO part
    VALUES ('xyz-9-1', 'manufactured part', 'M', 0);
    INSERT INTO part
    VALUES ('xyz-9a', 'manufactured part', 'M', 0);
    INSERT INTO part
    VALUES ('raw-1', 'purchased raw material', 'P', 212);
    INSERT INTO part
    VALUES ('raw-2', 'purchased raw material', 'P', 75.5);
    INSERT INTO part
    VALUES ('XYZ-100', 'manufactured part', 'M', 0);
    INSERT INTO part
    VALUES ('(OPEN)', '(not in use)', 'Y', 0);
    INSERT INTO part
    VALUES ('XYZ-100-1', 'manufactured part', 'M', 0);
    INSERT INTO part
    VALUES ('XYZ-100-2', 'manufactured part', 'M', 1);
    INSERT INTO part
    VALUES ('XYZ-100-3', 'manufactured part', 'M', 0);
    INSERT INTO part
    VALUES ('XYZ-100-4', 'manufactured part', 'M', 2);
    INSERT INTO part
    VALUES ('XYZ-100-A', 'manufactured part', 'M', 0);
    INSERT INTO bill
    VALUES ('2008072153100150000','XYZ-100','xyz-1',3,'1','****',0,'RL','M','01-Jan-2050','01-Jan-1900');
    INSERT INTO bill
    VALUES ('2008072153100150000','XYZ-100','XYZ-100-1',1,'1','****',0,'RL','M','01-Jan-2050','01-Jan-1900');
    INSERT INTO bill
    VALUES ('2008072153100150000','XYZ-100-1','xyz-1',2,'1','****',1,'RL','M','01-Jan-2050','01-Jan-1900');
    INSERT INTO bill
    VALUES ('2008072153100150000','XYZ-100-1','XYZ-100-2',3,'1','****',0,'RL','M','01-Jan-2050','01-Jan-1900');
    INSERT INTO bill
    VALUES ('2008072153100150000','XYZ-100-2','xyz-2',6,'1','****',2,'RL','M','01-Jan-2050','01-Jan-1900');
    INSERT INTO bill
    VALUES ('2008072153100150000','XYZ-100-2','xyz-4',6,'1','****',2,'IN','M','01-Jan-2050','01-Jan-1900');
    INSERT INTO bill
    VALUES ('2008072153100150000','XYZ-100-2','xyz-100-3',1,'1','****',0,'RL','M','01-Jan-2050','01-Jan-1900');
    INSERT INTO bill
    VALUES ('2008072153100150000','XYZ-100-3','xyz-3',8,'1','****',1,'RL','M','01-Jan-2050','01-Jan-2000');
    INSERT INTO bill
    VALUES ('2008072153100150000','XYZ-100-3','xyz-3a',8,'1','****',1,'RL','M','01-Jan-2000','01-Jan-1900');
    INSERT INTO bill
    VALUES ('2008072153100150000','XYZ-100-3','XYZ-100-4',4,'1','****',0,'RL','M','01-Jan-2050','01-Jan-1900');
    INSERT INTO bill
    VALUES ('2008072153100150000','XYZ-100-3','XYZ-100-A',2,'1','****',2,'RL','M','01-Jan-2050','01-Jan-1900');
    INSERT INTO bill
    VALUES ('2008071153100150000','XYZ-100-3','(OPEN)',2,'1','****',0,'RL','E','01-Jan-2050','01-Jan-1900');
    INSERT INTO bill
    VALUES ('2008071153100150000','XYZ-100-3','xyz-9-1',2,'1','****',0,'RL','H','01-Jan-2050','01-Jan-1900');
    INSERT INTO bill
    VALUES ('2008072153100150000','XYZ-100-4','raw-1',8.75,'1','****',0,'RL','M','01-Jan-2050','01-Jan-1900');
    INSERT INTO bill
    VALUES ('2008072153100150000','XYZ-100-A','raw-2',3.75,'1','****',0,'RL','M','01-Jan-2050','01-Jan-1900');
    INSERT INTO bill
    VALUES ('2008075911100150000','xyz-9-1','xyz-9a',1,'1','****',0,'RL','G','01-Jan-2050','01-Jan-1900');
    INSERT INTO bill
    VALUES ('2008087711100150000','xyz-9a','raw-2',3.75,'1','****',0,'RL','G','01-Jan-2050','01-Jan-1900');Sample data displayed in table format:
    --PART table (from insert statements above)
    part_nbr     part_desc          part_type     qty_on_hand
    xyz-1           purchased part          P          5
    xyz-2           purchased part          P          1
    xyz-3           purchased part          P          1
    xyz-3a           manufactured part     M          1
    xyz-4           purchased part          P          1
    xyz-9-1           manufactured part     M          0
    xyz-9a           manufactured part     M          0
    raw-1           purchased raw material     P          212
    raw-2           purchased raw material     P          75.5
    XYZ-100           manufactured part     M          0
    (OPEN)          (not in use)          Y          0
    XYZ-100-1     manufactured part     M          0
    XYZ-100-2     manufactured part     M          1
    XYZ-100-3     manufactured part     M          0
    XYZ-100-4     manufactured part     M          2
    XYZ-100-A     manufactured part     M          0
    --BILL table (from insert statements above)
    row_added_ts          bom_doc_nbr     comp_part_nbr     qty_per     qty_per_type     oper_nbr     comp_off_adj     status     view_code     end_eff_dt     begn_eff_dt
    2008072153100150000     XYZ-100          xyz-1          3     1          ****          0          RL     G          01-Jan-2050     01-Jan-1900
    2008072223100150000     XYZ-100          XYZ-100-1     1     1          ****          0          RL     M          01-Jan-2050     01-Jan-1900
    2008072411100150000     XYZ-100-1     xyz-1          2     1          ****          1          RL     M          01-Jan-2050     01-Jan-1900
    2008072459100150000     XYZ-100-1     XYZ-100-2     3     1          ****          0          RL     M          01-Jan-2050     01-Jan-1900
    2008072578100150000     XYZ-100-2     xyz-2          6     1          ****          2          RL     M          01-Jan-2050     01-Jan-1900
    2008072694100150000     XYZ-100-2     xyz-4          6     1          ****          2          IN     G          01-Jan-2050     01-Jan-1900
    2008072786100150000     XYZ-100-2     xyz-100-3     1     1          ****          0          RL     M          01-Jan-2050     01-Jan-1900
    2008072865100150000     XYZ-100-3     xyz-3          8     1          ****          1          RL     M          01-Jan-2050     01-Jan-2000
    2008073100100150000     XYZ-100-3     xyz-3a          8     1          ****          1          RL     M          01-Jan-2000     01-Jan-1900
    2008073159100150000     XYZ-100-3     XYZ-100-4     4     1          ****          0          RL     M          01-Jan-2050     01-Jan-1900
    2008073346100150000     XYZ-100-3     XYZ-100-A     2     1          ****          2          RL     M          01-Jan-2050     01-Jan-1900
    2008073478100150000     XYZ-100-3     (OPEN)          2     1          ****          0          RL     E          01-Jan-2050     01-Jan-1900
    2008073529100150000     XYZ-100-3     xyz-9-1          2     1          ****          0          RL     H          01-Jan-2050     01-Jan-1900
    2008073798100150000     XYZ-100-4     raw-1          8.75     1          ****          0          RL     M          01-Jan-2050     01-Jan-1900
    2008073811100150000     XYZ-100-A     raw-2          3.75     1          ****          0          RL     M          01-Jan-2050     01-Jan-1900
    2008075911100150000     xyz-9-1          xyz-9a          1     1          ****          0          RL     G          01-Jan-2050     01-Jan-1900
    2008087711100150000     xyz-9a          raw-2          3.75     1          ****          0          RL     G          01-Jan-2050     01-Jan-1900--What I want to get with my query (branches pruned off my tree)
    LEVEL     C_PART_NBR     C_PART_DESC          C_PART_TYPE     C_QTY_PER_P     C_QTY_PER_TYPE     C_QTY_ON_HAND     RQD_AT_OP     RQD_OFFSET     P_PART_NBR     P_QTY_ON_HAND
    1     XYZ-100-1     manufactured part     M          1          1          0          ****          0          XYZ-100          0
    2     XYZ-100-2     manufactured part     M          3          1          1          ****          0          XYZ-100-1     0
    3     xyz-100-3     manufactured part     M          1          1          0          ****          0          XYZ-100-2     1
    4     XYZ-100-4     manufactured part     M          4          1          2          ****          0          XYZ-100-3     0
    4     XYZ-100-A     manufactured part     M          2          1          0          ****          2          XYZ-100-3     0--What I actually get with my query (includes children of items that don't meet query criteria)
    LEVEL     C_PART_NBR     C_PART_DESC          C_PART_TYPE     C_QTY_PER_P     C_QTY_PER_TYPE     C_QTY_ON_HAND     RQD_AT_OP     RQD_OFFSET     P_PART_NBR     P_QTY_ON_HAND
    1     XYZ-100-1     manufactured part     M          1          1          0          ****          0          XYZ-100          0
    2     XYZ-100-2     manufactured part     M          3          1          1          ****          0          XYZ-100-1     0
    3     xyz-100-3     manufactured part     M          1          1          0          ****          0          XYZ-100-2     1
    4     XYZ-100-4     manufactured part     M          4          1          2          ****          0          XYZ-100-3     0
    4     XYZ-100-A     manufactured part     M          2          1          0          ****          2          XYZ-100-3     0
    5     xyz-9a          manufactured part     M          1          1          0          ****          0          xyz-9-1          0Edited by: user11033437 on Jul 30, 2009 7:27 AM (grammar)

  • Hierarchical query

    Hello, I have a challenge figuring out a BOM problem. I have two tables, one that holds the parent - child relation, and one that holds information about the products. What I need is a substract of the complete BOM. I'm only interested in the parts that exists in the tmp_parts table. The result of the query should "jump over" the parts that are not in the tmp_parts table. So based on the initial tables:
    create table tmp_bom (parent varchar2(256), child varchar2(256));
    create table tmp_parts (part varchar2(256))
    insert into tmp_bom(parent, child) values('A','B');
    insert into tmp_bom(parent, child) values('A','C');
    insert into tmp_bom(parent, child) values('C','D');
    insert into tmp_parts(part) values('A');
    insert into tmp_parts(part) values('B');
    insert into tmp_parts(part) values('D');
    The result of the query should be:
    A,B
    A,D
    ...because C is not in the tmp_parts table, D should be a child of A instead of C.
    Anyone having an idea of achieving this?
    - Paul

    Hi, Paul,
    user1754603 wrote:
    Thank you for your reply.
    Sorry, I forgot to inform about the Oracle version, which is 10g (10.2.0.4.0).
    I wanted to have the output as a table, just like the format in the tmp_bom table, except that the parts not in tmp_parts should be left out. I see!
    The query I posted on Wednesday gave this output:
    PATH
    A,B
    A,Dbut you want this instead:
    PARENT     CHILD
    A          B
    A          DThat illustrates why posting formatted results, between \ tags, is such a good idea.
    So based on your query, I wrote this:
    SELECT CASE WHEN parent NOT IN (SELECT * FROM tmp_parts) THEN real_parent ELSE parent END parent, child
    FROM (SELECT REGEXP_REPLACE (SYS_CONNECT_BY_PATH (p.part, ','), '.*(\w),?$', '\1') real_parent, b.parent, b.child
    FROM tmp_bom b, tmp_parts p
    WHERE b.parent = p.part(+) AND child IN (SELECT part FROM tmp_parts)
    START WITH b.parent NOT IN (SELECT child FROM tmp_bom)
    CONNECT BY b.parent = PRIOR b.child)This might not be the smoothest way to query, so any suggestions on making it better is of course appreciated :)
    - PaulAnother approach is to do a bottom-up query, where you start with the all the children that you want in the result set, and use CONNECT BY to find their ancestors.  You can stop as soon as you find one that is in the tmp_parts table; that's what the condition "CONNECT BY ... p.part IS NULL" does.SELECT DISTINCT     b.parent
    ,          CONNECT_BY_ROOT b.child     AS child
    FROM          tmp_bom     b
    LEFT OUTER JOIN     tmp_parts     p     ON     b.child     = p.part
    WHERE CONNECT_BY_ISLEAF     = 1
    START WITH p.part IS NOT NULL
    CONNECT BY b.child = PRIOR b.parent
         AND p.part IS NULL
    I suspect this will be faster, since it avoids the sub-query in the START WITH clause (in fact, it avoids sub-queries altogether, where the query you posted uses 4 of them), stops the CONNECT BY as soon as possible, and doesn't need regular expressions.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Hierarchical Query with Rollup Sum (CONNECT BY with GROUP BY ROLLUP)

    Hi all,
    Imagine the following scenario: i have an ACCOUNT table which holds accounts and their hierarchy (currently 5 levels), and a BALANCE table which holds balance records for the accounts. Only CHILD accounts (level 5) have records in the BALANCE table. Simple example:
    CREATE TABLE accounts (account_code VARCHAR2(30), parent_account VARCHAR2(30), account_desc VARCHAR2(400));
    CREATE TABLE balances (account_code VARCHAR2(30), balance_amount NUMBER(18,2));
    INSERT INTO ACCOUNTS VALUES ('TOT',NULL,'Total');
    INSERT INTO ACCOUNTS VALUES ('ANA1','TOT','General Expenses');
    INSERT INTO ACCOUNTS VALUES ('4801001','ANA1','Small Expenses');
    INSERT INTO ACCOUNTS VALUES ('4801002','ANA1','Transportation');
    INSERT INTO ACCOUNTS VALUES ('ANA2','TOT','Health Expenses');
    INSERT INTO ACCOUNTS VALUES ('4802001','ANA2','Healthcare');
    INSERT INTO ACCOUNTS VALUES ('4802002','ANA2','Facilities');
    INSERT INTO BALANCES VALUES ('4801001', 2000);
    INSERT INTO BALANCES VALUES ('4801002', 1000);
    INSERT INTO BALANCES VALUES ('4802001', 3000);
    INSERT INTO BALANCES VALUES ('4802002', 4000);What i need in this scenario is to run a hierarchical query, where for each node i compute the sum of all its children (In LEAF nodes which are the child accounts, this sum is the value in BALANCES itself). Final Result would be:
    TOT -> 10000
      ANA1 -> 3000
        4801001 -> 2000
        4801001 -> 1000
      ANA2 -> 7000
        4802001 -> 3000
        4802002 -> 4000I have tried various ways, and found out a workaround which works for a fixed amount of levels, basically it builds the hierarchy and computes the SYS_CONNECT_BY_PATH, then splits this as a regular expression and uses GROUP BY ROLLUP to compute the higher levels. Then i assemble it again, now with the computed values. Below is the example query:
    select level
        , NVL (vfinal.child_account,'TOTAL') ||' - '||
                            ( SELECT account_desc
                                FROM accounts
                               WHERE account_code = vfinal.child_acct ) account_name
         , to_char(sum_bal, 'fm999g999g999g990') as rolled_up_balance
      from
    select coalesce( princ.lvl3, princ.lvl2, princ.lvl1 ) child_acct
         , DECODE ( princ.lvl2 , NULL
                                     , NULL
                                     , DECODE ( princ.conta_lvl3, NULL
                                     , princ.conta_lvl1,princ.conta_lvl2 ) ) parent_acct
         , sum(princ.balance_amount) sum_bal
    from (
    select hier.lvl1
         , hier.lvl2
         , hier.lvl3
         , hier.parent_account
         , hier.account_code child_acc
         , bal.balance_amount
      from ( select level 
                  , sys_connect_by_path( account_code, '/' ) hierarchy_acct
                  , REGEXP_SUBSTR(sys_connect_by_path( account_code, '/' ),'[^/]+',1,3) lvl3
                  , REGEXP_SUBSTR(sys_connect_by_path( account_code, '/' ),'[^/]+',1,2) lvl2
                  , REGEXP_SUBSTR(sys_connect_by_path( account_code, '/' ),'[^/]+',1,1) lvl1
                  , account_code
                  , parent_account 
               from accounts acc
               where level <= 3
               start with parent_account is null
               connect by nocycle prior account = parent_account
               order siblings by parent_account
               ) hier
          , balances  bal
      where bal.cod_conta  = hier.account_code
    ) princ
    where princ.lvl1 is not null
    group by rollup ( princ.lvl1
                    , princ.lvl2
                    , princ.lvl3 )
    order by princ.conta_lvl1
           , princ.conta_lvl2
           , princ.conta_lvl3
    ) vfinal
    where child_acct is not null
    start with parent_acct is null
    connect by nocycle prior child_acct = parent_acctAll said and done, what i need is to do the same thing for infinite levels, because this query has 3 fixed levels. Do you know how can i structure a new query where, independently of the number of levels, the parent sums are all rolled up like this?
    Thanks a lot in advance! Best Regards!
    Thiago
    Edited by: Thiago on Sep 6, 2011 11:31 AM
    Edited by: Thiago on Sep 6, 2011 1:01 PM

    Hi,
    Thiago wrote:
    Hi all,
    Imagine the following scenario: i have an ACCOUNT table which holds accounts and their hierarchy (currently 5 levels), and a BALANCE table which holds balance records for the accounts. Only CHILD accounts (level 5) have records in the BALANCE table. Simple example:
    CREATE TABLE accounts (account_code VARCHAR2(30), parent_account VARCHAR2(30), account_desc VARCHAR2(400));
    CREATE TABLE balances (account_code VARCHAR2(30), balance_amount NUMBER(18,2));
    INSERT INTO ACCOUNTS ('TOT',NULL,'Total');
    INSERT INTO ACCOUNTS ('ANA1','TOT','General Expenses');
    INSERT INTO ACCOUNTS ('4801001','ANA1','Small Expenses');
    INSERT INTO ACCOUNTS ('4801002','ANA1','Transportation');
    INSERT INTO ACCOUNTS ('ANA2','TOT','Health Expenses');
    INSERT INTO ACCOUNTS ('4802001','ANA2','Healthcare');
    INSERT INTO ACCOUNTS ('4802002','ANA2','Facilities');
    INSERT INTO BALANCES ('4801001', 2000);
    INSERT INTO BALANCES ('4801001', 1000);
    INSERT INTO BALANCES ('4802001', 3000);
    INSERT INTO BALANCES ('4802001', 4000);
    Thanks for posting the CREATE TABLE and INSERT statements. Remember why you do it: so that the people who want to help you can re-create the problem and test their ideas. If the statments don't work, then they are not so useful. None of the INSERT statements you posted work: they all need a VALUES keyword. Please test those statments before you post them.
    Also, make sure that the reuslts you post correspond to the sample data you post. In your sample data, there are no rows in balances for account_codes '4801002' or '4802002'.
    I think you want something like this:
    WITH  connect_by_results      AS
         SELECT     CONNECT_BY_ROOT account_code     AS root_account_code
         ,     account_code
         FROM     accounts
                             -- NOTE: No START WITH clause
         CONNECT BY     parent_account     = PRIOR account_code
    SELECT       c.root_account_code     || ' -> '
                          || TO_CHAR (SUM (b.balance_amount))     AS txt
    FROM           connect_by_results  c
    LEFT OUTER JOIN      balances          b  ON  c.account_code = b.account_code
    GROUP BY  c.root_account_code
    ;

  • Sql query to retrieve records in parent sibling relationship in a table

    I need help to write this Sql query on a table where it has the primary_id, parent_id, and sibling_id. A new row can be created with or without the parent_id and sibling_id. However most of the new rows are created from an existing row and the primary_id
    of the existing row is inserted to the parent_id of the new row. This can go on for many many rows such as (B's parent_id has A primary_id, A's sibling_id has B primary_id), (C's parent_id has B primary_id, B's sibling_id has C primary_id), (D's
    parent_id has C primary_id, C's sibling_id has D primary_id), What I want is when user pass on a primary_id on a row, the query will give me back all the related parent_id or sibling_id records. For example User pass the A's primary_id the query will
    give me back the Row B and Row C as a sibling rows or user pass the C's primary_id the query should give me back row B and Row A as parent rows. Thanks
    Kahlua

    Check http://social.technet.microsoft.com/wiki/contents/articles/21062.t-sql-hierarchical-table-sorting-with-a-parent-child-relation.aspx
    For every expert, there is an equal and opposite expert. - Becker's Law
    My blog
    My TechNet articles

  • A help with a hierarchical query

    I've got two tables:
    FOLDERS where relevant fields are: folderId, parentFolderId, folderQuota
    and DOCUMENTS where the relevant fields are: folderId, size
    FOLDERS is hierarchical - parentFolderId of a child's folder is set to folderId of the parent
    folderQuota is nullable (quota not set)
    Now, I need to execute a query with the following recursive logic
    <i>function calcQuota (folderIdpar, isFirstpar) {
    if (not isFirstpar) and (folderQuota of folder with folderIdpar is not null) return folderQuota;
    return size of all documents where folderId = folderIdpar + calcQuota (folderId of all children, false);
    }</i>
    (I hope the pseudocode is understandable - the query is executed as <i>calcQuota(originalFolderId, true)</i>).
    Now, my question is if I can achieve it with a single hierarchical query, or if I have to implement it as a recursive stored procedure.
    Thanks!
    P.S. I'm using Oracle XE (10g)

    OK,
    I will need to create it (in real life it is created by an application), so I hope I will make it correct. If not, it should be easy to fix.
    create table folders (
    folder_id number primary key
    parent_folder_id number,
    quota number
    create table documents (
    document_id number primary key
    folder_id number,
    size number
    INSERT INTO folders (folder_id, quota) VALUES (1, 1);
    INSERT INTO folders (folder_id, parent_folder_id, quota) VALUES (2, 1, 2);
    INSERT INTO folders (folder_id, parent_folder_id) VALUES (3, 1);
    INSERT INTO folders (folder_id, parent_folder_id, quota) VALUES (4, 2, 4);
    INSERT INTO folders (folder_id, parent_folder_id) VALUES (5, 2);
    INSERT INTO folders (folder_id, parent_folder_id, quota) VALUES (6, 3, 8);
    INSERT INTO folders (folder_id, parent_folder_id) VALUES (7, 3);
    INSERT INTO documents (document_id, folder_id, size) VALUES (1, 1, 16);
    INSERT INTO documents (document_id, folder_id, size) VALUES (2, 2, 32);
    INSERT INTO documents (document_id, folder_id, size) VALUES (3, 3, 64);
    INSERT INTO documents (document_id, folder_id, size) VALUES (4, 3, 128);
    INSERT INTO documents (document_id, folder_id, size) VALUES (5, 4, 256);
    INSERT INTO documents (document_id, folder_id, size) VALUES (6, 5, 512);
    INSERT INTO documents (document_id, folder_id, size) VALUES (7, 6, 1024);
    INSERT INTO documents (document_id, folder_id, size) VALUES (8, 7, 2048);
    running the query for folder_id = 1 should return 1 + 2 + 64 + 128 + 8 + 2048 = 2251
    running the query for folder_id = 2 should return 4 + 512 = 516
    I have decided for this data, because it allows to track what values (folder.quota or document.size) is included in the result.
    (it is the knapsack problem - see http://en.wikipedia.org/wiki/Knapsack_problem)
    P.S. I'm leaving for three weeks, so I will come back after that.

  • How to use order by with hierarchical query

    I have a hierarchical query basically it brings back an organization chart. We start with a manager's id, get all that person's employees. If any of the employees is also a manager I want to get that person's employees and return them right after that person. I won't bother with the whole query but relevant part is:
           START WITH em.mgr_id = pi_mgr_id
          CONNECT BY nocycle PRIOR em.emp_id = em.mgr_id;Where pi_mgr_id is a parameter passed to the procedure and em is the alias for the emp_mgr_relationship table which contains emp_id and mgr_id. This works fine. What I want now is for the employees who work for the same manager to appear in name order. The table which contains the employee names is aliased as pe and the name column is called name1. I added the following:
           START WITH em.mgr_id = pi_mgr_id
          CONNECT BY nocycle PRIOR em.emp_id = em.mgr_id
            order by pe.name1;But that put the entire list in name order. What I want is for employees who work for the same manager to be in name order. Let's the manager whose organization I want is named Frank. What I'd like to get is this
    EMP_NAME    MGR_NAME
    Allen       Frank
    Beth        Frank
    Alex        Beth
    Charles     Beth
    Ed          Beth
    Dean        Frank
    George      Frank
    Benny       George
    David       George
    Sam         George
    Dan         Sam
    Harry       Sam
    John        Sam
    Terry       George
    James       Frank
    Ken         Frank
    Mike        Ken
    Warren      KenHow do I get the list in this order?
    Edited by: kendenny on Jul 28, 2010 7:31 AM

    Make use of ORDER SIBLINGS clause in hierarchial queries to set the order by child columns.
    START WITH em.mgr_id = pi_mgr_id
          CONNECT BY nocycle PRIOR em.emp_id = em.mgr_id
            *order siblings by name1;*

  • Depth first in hierarchical query

    Does anybody know how to make a depth first run through of a
    hierarchical query using START WITH ... CONNECT BY PRIOR???

    Allright, here comes the details:
    Imagine that you need to perform a depth first run of a table
    that looks like this:
    id
    parent_id
    priority
    depth
    attribute1
    attribute2
    id is primary key and parent_id foreign key to id, i.e. it
    references id. The priority is forth numbered from 1 to n if n
    children are attached to the same parent. The depth indicates
    the depth in the tree the row is. Example rows:
    1 null 1 0 foo bar ...
    2 1 2 1 foobar barfoo ...
    3 1 1 1 barbar foofoo ...
    4 null 2 0 foo bar ...
    5 2 1 2 foofoobar barfoofoo ...
    6 2 3 2 foobarfoo barfoobar ...
    7 2 2 2 foofoofoo barbarbar ...
    8 6 1 3 foooooooooo baaaaaaaaar ...
    9 1 3 1 fooooo baaaar ...
    The desired result should then be (assume that all attributes
    are selected):
    1 null 1 0 foo bar ...
    3 1 1 1 barbar foofoo ...
    2 1 2 1 foobar barfoo ...
    5 2 1 2 foofoobar barfoofoo ...
    7 2 2 2 foofoofoo barbarbar ...
    6 2 3 2 foobarfoo barfoobar ...
    8 6 1 3 foooooooooo baaaaaaaaar ...
    9 1 3 1 fooooo baaaar ...
    4 null 2 0 foo bar ...
    My attempt was to try something like:
    SELECT id, parent_id, priority, attribute1, attribute2, ...
    FROM table
    CONNECT BY PRIOR id = parent_id START WITH id = ?
    ORDER BY depth, priority
    I know that the depth can be obtained from CONNECT BY PRIOR, but
    I use the depth in other SQLs, so just assumes that you have
    it...
    This SELECT ofcause only selects from a given id and down, but
    that is also ok; we can just start with id = 1. And the SELECT
    needs to be given the root id, since that is the way the
    application works...
    But this does not work, since it groups by depth thus return all
    children (c1...cN) at depth i for parent_id x before the
    children of a child in (c1...cN) at depth i+1.
    So, I guess the question is... If the above SELECT can be used
    showhow, then
    SELECT id, parent_id, priority, attribute1, attribute2, ...
    FROM table
    CONNECT BY PRIOR id = parent_id START WITH id = ?
    ORDER BY __WHAT_GOES_HERE___, priority
    or if not, please state a SELECT statement that does the trick!
    Regards
    Sxren

  • Reg : Hierarchical Query(Using Connect By)

    Hi all,
    I got the result with the hierarchical query as :
    */qxxh*
    */qxxh/jxobcbg*
    */qxxh/jxobcbg/n00wcp4*
    */qxxh/jxobcbg/n00wcp4/x000263*
    */qxxh/jxobcbg/n00wcp4/x000263/p0263*
    */qxxh/jxxocbg*
    */qxxh/jxxocbg/n00voc1*
    */qxxh/jxxocbg/n00voc1/x000589*
    */qxxh/jxxocbg/n00voc1/x000589/p0589*
    */qxxh/jxuwxxh*
    */qxxh/jxuwxxh/n00xpxf*
    */qxxh/jxuwxxh/n00xpxf/m00bxpl*
    */qxxh/jxuwxxh/n00xpxf/m00bxpl/x000522*
    */qxxh/jxuwxxh/n00xpxf/m00bxpl/x000522/p0522*
    Here I want to select only maximum path . Here I used "SYS_CONNECT_BY_PATH"
    Please let meknow how to do this ?
    Thanks in advance .
    Edited by: udeffcv on Dec 9, 2009 10:03 PM

    udeffcv wrote:
    Hi all,
    I got the result with the hierarchical query as :
    */qxxh*
    */qxxh/jxobcbg*
    */qxxh/jxobcbg/n00wcp4*
    */qxxh/jxobcbg/n00wcp4/x000263*
    */qxxh/jxobcbg/n00wcp4/x000263/p0263*
    */qxxh/jxxocbg*
    */qxxh/jxxocbg/n00voc1*
    */qxxh/jxxocbg/n00voc1/x000589*
    */qxxh/jxxocbg/n00voc1/x000589/p0589*
    */qxxh/jxuwxxh*
    */qxxh/jxuwxxh/n00xpxf*
    */qxxh/jxuwxxh/n00xpxf/m00bxpl*
    */qxxh/jxuwxxh/n00xpxf/m00bxpl/x000522*
    */qxxh/jxuwxxh/n00xpxf/m00bxpl/x000522/p0522*
    Here I want to select only maximum path . Here I used "SYS_CONNECT_BY_PATH"
    Please let meknow how to do this ?
    Thanks in advance .
    Edited by: udeffcv on Dec 9, 2009 10:03 PMwhat do you mean by maximum path?? is it...
    */qxxh/jxobcbg/n00wcp4/x000263/p0263*
    */qxxh/jxxocbg/n00voc1/x000589/p0589*
    */qxxh/jxuwxxh/n00xpxf/m00bxpl/x000522/p0522*
    is it child nodes??
    then you might like to see
    CONNECT_BY_ISLEAF pseudo column..example you can find it in below link
    http://download.oracle.com/docs/cd/B14117_01/server.101/b10759/pseudocolumns001.htm#sthref670
    Ravi Kumar

Maybe you are looking for

  • I am having having trouble with my macbook pro

    Hi, I recently purchased a macbook pro off of ebay it is a year 2007. It was running great until I tried to install os x snow leopard. Everytime it failed and evetually my computer had a kernel panic and now I cannot get past it. Everytime I restart

  • IPhone 4 won't show up in iTunes - can't sync

    Spent the day yesterday talking with several Apple technical advisors and still can't solve this seemingly easy fix. I restored Windows 7 to earlier state and lost iTunes. I reinstalled but iTunes will not recognize my iPhone. I've done everything th

  • RFBILA00 Alternative account number Missing

    Dear All, I  assigned operating general ledger accounts to financial statement version, and in GL master data, i have already assigned alternative account number to them.  but when i run RFBILA00 report, i turn on "accounts with zero balance" " ALV g

  • Output.Print printing all PDFs double-sided

    Hello According to the following article it is possible to configure a PDF to print single or double sided in the Adobe LiveCycle Designer: http://help.adobe.com/en_US/livecycle/9.0/designerHelp/index.htm?content=000089.html#15813 85 I follow these e

  • Flash Troubleshooting in IE

    I've been having a problem with Flash for a couple of months, and I'm interested in straightening this out. I'm running XP Home SP2, and IE6. Often, when browsing, I come across a link to a Flash application (are they called "applications"?). When I