Need sort child record in "start.. connect by"

MY SQL IS LIKE
select parent_item,compon_item,qty_ass,level
from m1
start with parent_item = 'E.29-401'
connect by parent_item = PRIOR compon_item
i want resul in order of compon_item in EACH Level

order siblings by compon_item                                                                                                                                                                                                                           

Similar Messages

  • Union on tables with parent-child records and Sorting

    Hi,
    I have an application that has an existing query which returns org units (parent and child) from organization table with a sort on createddate +  org_id combination
    WITH Org_TREE AS (
    SELECT *, null as 'IS_DELETED', convert (varchar(4000), convert(varchar(30),CREATED_DT,126) + Org_Id) theorderby
    FROM Organization WHERE PARENT_Org_ID IS NULL and case_ID='43333'
    UNION ALL
    SELECT a1.*, null as 'IS_DELETED', convert (varchar(4000), a2.theorderby + convert(varchar(30),a1.CREATED_DT,126) + a1.Org_Id)
    FROM Organization a1 INNER JOIN Org_TREE a2 ON a1.PARENT_Org_ID = a2.Org_Id and case_ID='43333'
    SELECT * FROM Org_TREE order by theorderby
    I have created a new log table for organization 'Organization_Log' with exact columns as Organization table with an additional 'IS_DELETED' bool column.
    Questions:
    I need to modiy the query,
    1. To display the parent and child records both from the organization table and organization_log table.
    2. the sort on the result should be based on 'Organization Name' column asc. First with parent org and the child org underneath it. For eg.
    aaa
    ==>fff
    ==>ggg
    bbb
    ==> aaa
    ==> hhh
    Any help on how the query should be constructed?
    Thanks
    gkol

    @Visakh16,
    I am getting...
    All queries combined using a UNION, INTERSECT or EXCEPT operator must have an equal number of expressions in their target lists.
    The problem is that you will have different number of columns in both log and Organization and Organizationlog tables. UNION/UNION ALL expect the same number of columns.
    Try the below:
    WITH Org_Log_TREE AS (
    SELECT Organization_name,Org_id,Parent_Org_id, IS_DELETED, CAST(Organization_Name AS varchar(max)) AS theorderby,1 AS level
    FROM Organization_Log WHERE PARENT_Org_ID IS NULL and case_ID='43333'
    UNION ALL
    SELECT a1.Organization_name,a1.Org_id,a1.Parent_Org_id, a1.IS_DELETED, CAST(a2.theorderby +'/' + CAST(a1.Organization_Name AS varchar(1000)) AS varchar(max)),a2.Level + 1
    FROM Organization_Log a1 INNER JOIN Org_Log_TREE a2 ON a1.PARENT_Org_ID = a2.Org_Id and case_ID='43333'
    ) ,Org_TREE AS (
    SELECT Organization_name,Org_id,Parent_Org_id, NULL AS IS_DELETED, CAST(Organization_Name AS varchar(max)) AS theorderby,1 AS level
    FROM Organization WHERE PARENT_Org_ID IS NULL and case_ID='43333'
    UNION ALL
    SELECT a1.Organization_name,a1.Org_id,a1.Parent_Org_id,NULL AS IS_DELETED, CAST(a2.theorderby +'/' + CAST(a1.Organization_Name AS varchar(1000)) AS varchar(max)),a2.Level + 1
    FROM Organization a1 INNER JOIN Org_TREE a2 ON a1.PARENT_Org_ID = a2.Org_Id and case_ID='43333'
    SELECT * FROM Org_Log_TREE
    UNION ALL
    SELECT * FROM Org_TREE
    ORDER BY LEFT(theorderby,CHARINDEX('/',theorderby + '/')-1),Level

  • Need Sorter java  file   for sorting the records in webdynpro java

    Hi  Gurus
       I  had urgent requirement please give your inputs
       In my webdynpro java i need to sort entire records in table
       I now we need One sorter java class please provide that java file
       please suggest the all the steps how  to do
    Thanks
    renu.

    1. Implement class comparator wich will compare records according your sort preferencies,
    like this:
         public class record_Comparator implements Comparator{
              public int compare(Object emp1, Object emp2){
          // here is your code for return -1if 'before'  or 0 if equal or 1if 'after'
                   int stepId_1 = ((record)emp1).get_someValue();       
                   int stepId_2 = ((record)emp2).get_someValue();
                   if(stepId_1 > stepId_2)
                        return 1;
                   else if(stepId_1 < stepId_2)
                        return -1;
                   else
                        return 0;   
    than call method sort() with your collection of records,
    like this:
    Collections.sort(record_collection, new record_Comparator());

  • Need PL/SQL Command for to check all rows value for child record and update

    Hi All,
    i want to update one field following by
    one to many relationship for example
    in child applet status field is value is "Closed" for all child record then parent value also should update to closed
    Note: if one child record field status is "Open" don't do the update operation

    You can do it in single UPDATE operation.
    Here is sample & Result:
    create table PA (id varchar2(3), name varchar2(12), STATUS varchar2(12));
    insert into pa values('001','Cary','Open');
    insert into pa values('002','TOM','Open');
    create table boy (par_id varchar2(3), id varchar2(4), name varchar2(12), status varchar2(12));
    insert into boy values('001','ABC1','Cary','Open');
    insert into boy values('001','ABC2','Mac','Closed');
    insert into boy values('001','ABC3','Ray','Closed');
    insert into boy values('001','ABC4','NALLY','Open');
    insert into boy values('002','ABC5','ME','Closed');
    insert into boy values('002','ABC6','SHE','Closed');
    UPDATE PA
    SET STATUS='Closed'
    WHERE NOT EXISTS
      (SELECT 1
      FROM BOY
      WHERE BOY.PAR_ID=PA.id
      GROUP BY BOY.PAR_ID,
        BOY.STATUS
      HAVING SUM(DECODE(BOY.STATUS,'Open',1,'Closed',0,0))>0
    select * from pa;
    001     Cary     Open
    002     TOM     Closed

  • Parent/child records from same table

    I want to create a query that is a union such that the 2nd resultset is based on the 1st resultset. I have a table that has parent/child records in the same table.
    Table: EVENTS
    EVENT_ID
    PARENT_EVENT_ID
    CREATED_DATE
    (other columns)
    if PARENT_EVENT_ID is null then it is a parent record, else it is a child record. I want to select all parent records then union them with all the associated child records...something like this:
    select * from EVENTS where CREATED_DATE < sysdate - 90 and PARENT_EVENT_ID is null -- All parents
    union
    select * from EVENTS where PARENT_EVENT_ID in (select EVENT_ID from EVENTS where CREATED_DATE < sysdate - 90 and PARENT_EVENT_ID is null) -- include any children of parents selected from above
    This works but it's kind of ugly, I want to avoid using the sub-select in the 2nd because it is a repeat of the 1st statement, is there a way to alias the first statement and just refer to it in the 2nd query?

    Hi,
    kev374 wrote:
    Thanks, one question...
    I did a test and it seems the child rows have to also satisfy the parent row's where clause, take this example:
    EVENT_ID|PARENT_EVENT_ID|CREATED_DATE
    2438 | (null) | April 9 2013
    2439 | 2438 | April 11 2013
    2440 | 2438 | April 11 2013
    select * from EVENTS where CREATED_DATE < sysdate - 9
    start with EVENT_ID = 2438
    connect by PARENT_EVENT_ID = prior EVENT_IDSo you've changed the condition about only wanting roots and their children, and now you want descendants at all levels.
    This pulls in record #2438 (per the sysdate - 9 condition) but 2439 and 2440 are not connected. Is there a way to supress the where clause evaluation for the child records? I just want to pull ALL child records associated with the parent and only want to do the date check on the parent.Since the roots (the only rows you want to exclude) have LEVEL=1, you can get the results you requested like this:
    WHERE   created_date  < SYSDATE - 9
    OR      LEVEL         > 1However, since you're not ruling out the grandchildren and great-grandchildren any more, why wouldn't you just say:
    SELECT  *
    FROM    events
    WHERE   created_date     < SYSDATE - 9
    OR      parent_event_id  IS NOT NULL;?
    CONNECT BY is slow. Don't use it if you don't need it.
    If you x-reference my original query:
    select * from EVENTS where CREATED_DATE < sysdate - 90 and PARENT_EVENT_ID is null -- All parents
    union
    select * from EVENTS where PARENT_EVENT_ID in (select EVENT_ID from EVENTS where CREATED_DATE < sysdate - 90 and PARENT_EVENT_ID is null) -- include any children of parents selected from above
    The 2nd select does not apply the created_date < sysdate - 90 on the children but rather pulls in all related children :)Sorry; my mistake. That's what happens when you don't post sample data, and desired results; people can't test their solutions and find mistakes like that.

  • Cdc- deletion of parent- child records

    Hi,
    I am working with CDC-consistent feature in odi.
    Here my scenario is, I have a record say 120 (primary key) in table A(parent source table) and it is used as a foreign key in Table B.
    both child and parent are inserted into the concerned tables of target.
    Now i want to delete this 120 record from target parent and child tables.
    IN the pkg i arranged the pkg scenarios as follows
    odiwaitforlogdata----->source model(with extenwindow and lock subscriber option selected)------>parent pkg scenario------>child pkg scenario----->source mode(with unlock subscriber and purge journal options). ------------> This works fine for insert and update.
    odiwaitforlogdata----->source model(with extenwindow and lock subscriber option selected)------>child pkg scenario--------->parent pkg scenario----->source mode(with unlock subscriber and purge journal options). ------------> This works fine for delete.
    Can't I achieve these two in one pkg
    Please Guide.
    Regards,
    Chaitanya.

    Hi,
    kev374 wrote:
    Thanks, one question...
    I did a test and it seems the child rows have to also satisfy the parent row's where clause, take this example:
    EVENT_ID|PARENT_EVENT_ID|CREATED_DATE
    2438 | (null) | April 9 2013
    2439 | 2438 | April 11 2013
    2440 | 2438 | April 11 2013
    select * from EVENTS where CREATED_DATE < sysdate - 9
    start with EVENT_ID = 2438
    connect by PARENT_EVENT_ID = prior EVENT_IDSo you've changed the condition about only wanting roots and their children, and now you want descendants at all levels.
    This pulls in record #2438 (per the sysdate - 9 condition) but 2439 and 2440 are not connected. Is there a way to supress the where clause evaluation for the child records? I just want to pull ALL child records associated with the parent and only want to do the date check on the parent.Since the roots (the only rows you want to exclude) have LEVEL=1, you can get the results you requested like this:
    WHERE   created_date  < SYSDATE - 9
    OR      LEVEL         > 1However, since you're not ruling out the grandchildren and great-grandchildren any more, why wouldn't you just say:
    SELECT  *
    FROM    events
    WHERE   created_date     < SYSDATE - 9
    OR      parent_event_id  IS NOT NULL;?
    CONNECT BY is slow. Don't use it if you don't need it.
    If you x-reference my original query:
    select * from EVENTS where CREATED_DATE < sysdate - 90 and PARENT_EVENT_ID is null -- All parents
    union
    select * from EVENTS where PARENT_EVENT_ID in (select EVENT_ID from EVENTS where CREATED_DATE < sysdate - 90 and PARENT_EVENT_ID is null) -- include any children of parents selected from above
    The 2nd select does not apply the created_date < sysdate - 90 on the children but rather pulls in all related children :)Sorry; my mistake. That's what happens when you don't post sample data, and desired results; people can't test their solutions and find mistakes like that.

  • Facing problem while deleting a child record in hibernate.

    I am trying to update a child records i have following scenario
    master record (having one to many assciation with child table cascade=all in .hbm.xml configuration file) ===> customerInfo
    detail record set (having many to one assciation with master table cascade=all in .hbm.xml configuration file) ===> customerAccountsSet
    i do following steps to update a record
    1) get the customerInfo objetc from session successfully
    2) get the customerAccountsSet = customerInfo.getCustomerAccounts();
    3) traying to add a new customerAccount say customerAccount1 to be saved for the first time without primery key in it
    4) traying to update a customerAccount say customerAccount2 to be updated with primery key in it
    5) traying to add a delete customerAccount say customerAccount3 with primery key in it
    only step 5 is not executed properly as i can still see the deleted record in db , although save and update steps have been successfully completed in db.
    can anybody tell me whats going wrong here.code for steps 2,3,4,5 is as follows in the same order
    2)Set customerAccountSet = (Set) customerInfo.getCustomerAccounts();
    3)customerAccountSet.add(customerAccount);
    4)customerAccountSet.add(customerAccount);
    5)customerAccountSet.remove(customerAccount);

    Hi Nitesh,
    1) Java stack should be up while trying to connect to R/3 backend.
    2) You can check the JCOs by doing the following:
                           Type the following url   http://<server name>:<port number>
                           Click on Webdynpro Console
                           Enter the user name and password.(You need the system admin right on the EP to do the same)
                           You can find the JCOs.
    3) Better you contact the basis guy who had created the JCOs earlier and get the JCOs tested.
    Hope it helps.
    Regards.
    Rajat
    Edited by: Rajat Jain on Oct 12, 2009 1:47 PM

  • To find all the child records are processed before parent records

    Hi,
    When i am trying to process consignment pulls and my client is using third party tool to insert the data into interface tables. My logic is written in such a way that it should pick parent record associated with child but there is some delay in child records and not all the child records are being pulled with parent.
    In a brief, i need to write a condition in such a way that my parent cursor should pick all the child records with max(last_updated_date) and then it should be processed.
    eg: I have a family and need to catch bus with all my family members. I need to check now for the last family member who get into and should wait for atleast 2mins so as to ensure all my family members are in. I am unable to achieve this with count. Please do revert back soon.
    Details are below:
    CURSOR c_pull (p_pull_id NUMBER) IS----------------------------------parent cursor
    SELECT ecp.ROWID ROW_ID
    ,ecp.*
    FROM consignment_pulls ecp
    WHERE ecp.process_flag IN ( 2, 3 )
    AND ecp.pull_id > NVL(p_pull_id,0)
    ORDER BY ecp.pull_id
    FOR UPDATE OF ECP.PROCESS_FLAG NOWAIT;
    CURSOR c_line (p_pull_id NUMBER) IS----------------------------------child cursor
    SELECT ecpi.ROWID ROW_ID
    ,ecpi.*
    FROM consignment_pull_items ecpi
    WHERE ecpi.process_flag IN ( 2, 3 )
    AND ecpi.pull_id = p_pull_id
    FOR UPDATE OF ecpi.process_flag;
    Edited by: Prathyusha on Apr 5, 2012 12:07 AM
    Edited by: jerry on Apr 5, 2012 12:10 AM

    Hi Helios,
    Thanks for the info. But its not a concurrent request something like we can filter with start date and completion date. Its all about selection of records from headers and lines table and not able to make those selection of header records with a delay of say some 2minutes until all the child records are inserted.
    Thanks,
    Prathyusha.

  • Finding the complete hierarchy of all child records for a given root

    Hi,
    We need to find the hierarchy starting from a given root by exploding the hierarchy of each child present in the hierarchy.
    Consider a data as given below.
    Seq_no denotes a primary key.
    Child_id denotes the child node in the hierarchy
    Parent_id indicates the immediate parent of the child record
    Root_id denotes the starting point of the hierarchy.
    Within a given hierarchy the root_id will remain the same and parent_id will keep on changing as required.
    Seq_No Child_id     Parent_id     Root_id
    101          1          NULL     1
    102          2          1          1
    103          3          2          1
    104          4          1          1
    105          5          3          1
    106 4 NULL 4
    107 7 4 4
    108 8 4 4
    109 9 7 4
    110 3 NULL 3
    111 4 3 3
    112 5 3 3
    The requirement is to pull the hierarchy starting from a given root traversing down the path by exploding the hierarchy of each and every child present in that hierarchy. It is explained using below example.
    For root_id value as 4, the expected o/p is
    child_id path
    7 /7
    9 /7/9
    8 /8
    For root_id value as 3, the expected o/p is
    child_id path
    4 /4
    7 /4/7 ---> Hierarchy with root_id 4 gets exploded
    8 /4/8
    9 /4/7/9
    5 /5
    For root_id value as 1, the expected o/p is
    child_id path
    2 /2
    3 /2/3 ---> Hierarchy with root_id 3 gets exploded
    4 /2/3/4 ---> Hierarchy with root_id 4 gets exploded
    7 /2/3/4/7
    9 /2/3/4/7/9
    8 /2/3/4/8
    5 /2/3/5
    4 /4
    7 /4/7
    8 /4/8
    9 /4/7/9
    5 /5
    5 /2/3/5
    Also, additionally, if there exist any cyclic child records in the hierarchy, the exploding should stop there itself.
    CREATE TABLE xyz
    SEQ_NO NUMBER,
    ITEM_ID NUMBER,
    PARENT_ITEM_ID NUMBER,
    ROOT_ITEM_ID NUMBER
    Insert into xyz
    (SEQ_NO, ITEM_ID, ROOT_ITEM_ID)
    Values
    (1, 1, 1);
    Insert into xyz
    (SEQ_NO, ITEM_ID, PARENT_ITEM_ID, ROOT_ITEM_ID)
    Values
    (2, 2, 1, 1);
    Insert into xyz
    (SEQ_NO, ITEM_ID, PARENT_ITEM_ID, ROOT_ITEM_ID)
    Values
    (3, 3, 1, 1);
    Insert into xyz
    (SEQ_NO, ITEM_ID, PARENT_ITEM_ID, ROOT_ITEM_ID)
    Values
    (4, 4, 2, 1);
    Insert into xyz
    (SEQ_NO, ITEM_ID, ROOT_ITEM_ID)
    Values
    (8, 3, 3);
    Insert into xyz
    (SEQ_NO, ITEM_ID, PARENT_ITEM_ID, ROOT_ITEM_ID)
    Values
    (9, 10, 3, 3);
    Insert into xyz
    (SEQ_NO, ITEM_ID, PARENT_ITEM_ID, ROOT_ITEM_ID)
    Values
    (10, 11, 10, 3);
    Insert into xyz
    (SEQ_NO, ITEM_ID, ROOT_ITEM_ID)
    Values
    (12, 10, 10);
    Insert into xyz
    (SEQ_NO, ITEM_ID, PARENT_ITEM_ID, ROOT_ITEM_ID)
    Values
    (13, 12, 10, 10);
    Insert into xyz
    (SEQ_NO, ITEM_ID, ROOT_ITEM_ID)
    Values
    (14, 11, 11);
    Insert into xyz
    (SEQ_NO, ITEM_ID, PARENT_ITEM_ID, ROOT_ITEM_ID)
    Values
    (15, 13, 11, 11);
    Insert into xyz
    (SEQ_NO, ITEM_ID, PARENT_ITEM_ID, ROOT_ITEM_ID)
    Values
    (16, 14, 11, 11);
    Insert into xyz
    (SEQ_NO, ITEM_ID, PARENT_ITEM_ID, ROOT_ITEM_ID)
    Values
    (21, 23, 13, 11);
    Insert into xyz
    (SEQ_NO, ITEM_ID, PARENT_ITEM_ID, ROOT_ITEM_ID)
    Values
    (104, 16, 91, 14);
    Insert into xyz
    (SEQ_NO, ITEM_ID, PARENT_ITEM_ID, ROOT_ITEM_ID)
    Values
    (19, 16, 12, 10);
    Insert into xyz
    (SEQ_NO, ITEM_ID, PARENT_ITEM_ID, ROOT_ITEM_ID)
    Values
    (20, 17, 16, 10);
    Insert into xyz
    (SEQ_NO, ITEM_ID, ROOT_ITEM_ID)
    Values
    (101, 110, 110);
    Insert into xyz
    (SEQ_NO, ITEM_ID, PARENT_ITEM_ID, ROOT_ITEM_ID)
    Values
    (102, 111, 110, 110);
    Insert into xyz
    (SEQ_NO, ITEM_ID, PARENT_ITEM_ID, ROOT_ITEM_ID)
    Values
    (103, 17, 110, 110);
    Insert into xyz
    (SEQ_NO, ITEM_ID, PARENT_ITEM_ID, ROOT_ITEM_ID)
    Values
    (29, 31, 17, 10);
    Insert into xyz
    (SEQ_NO, ITEM_ID, PARENT_ITEM_ID, ROOT_ITEM_ID)
    Values
    (30, 32, 17, 10);
    Insert into xyz
    (SEQ_NO, ITEM_ID, PARENT_ITEM_ID, ROOT_ITEM_ID)
    Values
    (31, 33, 16, 10);
    Insert into xyz
    (SEQ_NO, ITEM_ID, PARENT_ITEM_ID, ROOT_ITEM_ID)
    Values
    (35, 49, 23, 11);
    Insert into xyz
    (SEQ_NO, ITEM_ID, ROOT_ITEM_ID)
    Values
    (41, 14, 14);
    Insert into xyz
    (SEQ_NO, ITEM_ID, PARENT_ITEM_ID, ROOT_ITEM_ID)
    Values
    (42, 91, 14, 14);
    Insert into xyz
    (SEQ_NO, ITEM_ID, PARENT_ITEM_ID, ROOT_ITEM_ID)
    Values
    (43, 92, 91, 14);
    COMMIT;
    Pl advise.
    Thanks,
    - Ajit
    Edited by: 952105 on Aug 10, 2012 10:44 AM

    My application tracks the product master that stores a product configuration along with its all child/sub-child records. There exists many such configurations for various parts.
    There can exist only one configuration for a given product at any point in time. But, at the same time, this product can be a part of other product configurations too (i.e. it can exist as a child in other hierarchies).
    Now, the business requirement is to pull the hierachy starting from a given product (as a root). This should also pull the hierarchy of each child/subchild existing under its hieararchy, if there exist a separate configuration for those child/subchild products.
    SET DEFINE OFF;
    CREATE TABLE XYZ
    ITEM_ID NUMBER,
    PARENT_ITEM_ID NUMBER,
    ROOT_ITEM_ID NUMBER,
    QUANTITY NUMBER,
    LINE_ID VARCHAR2(10 BYTE)
    Here, root_item_id denotes the product for which the configuration has been defined. All its child/sub-child records gets stored under this root_item_id itself. The parent_item_id column will get stored appropriately based on the immediate parent of the product under that hierarchy.
    Insert into XYZ
    (ITEM_ID, PARENT_ITEM_ID, ROOT_ITEM_ID, QUANTITY, LINE_ID)
    Values
    (2, 1, 1, 5, '1.1');
    Insert into XYZ
    (ITEM_ID, PARENT_ITEM_ID, ROOT_ITEM_ID, QUANTITY, LINE_ID)
    Values
    (3, 1, 1, 5, '1.2');
    Insert into XYZ
    (ITEM_ID, ROOT_ITEM_ID, QUANTITY, LINE_ID)
    Values
    (1, 1, 1, '1.0');
    Insert into XYZ
    (ITEM_ID, PARENT_ITEM_ID, ROOT_ITEM_ID, QUANTITY, LINE_ID)
    Values
    (4, 2, 1, 6, '1.1.1');
    Insert into XYZ
    (ITEM_ID, PARENT_ITEM_ID, ROOT_ITEM_ID, QUANTITY, LINE_ID)
    Values
    (10, 3, 3, 4, '1.1');
    Insert into XYZ
    (ITEM_ID, ROOT_ITEM_ID, QUANTITY, LINE_ID)
    Values
    (3, 3, 4, '1.0');
    Insert into XYZ
    (ITEM_ID, PARENT_ITEM_ID, ROOT_ITEM_ID, QUANTITY, LINE_ID)
    Values
    (11, 10, 3, 15, '1.1.1');
    Insert into XYZ
    (ITEM_ID, ROOT_ITEM_ID, QUANTITY, LINE_ID)
    Values
    (10, 10, 7, '1.0');
    Insert into XYZ
    (ITEM_ID, PARENT_ITEM_ID, ROOT_ITEM_ID, QUANTITY, LINE_ID)
    Values
    (12, 10, 10, 9, '1.1');
    Insert into XYZ
    (ITEM_ID, PARENT_ITEM_ID, ROOT_ITEM_ID, QUANTITY, LINE_ID)
    Values
    (16, 12, 10, 99, '1.1.1');
    Insert into XYZ
    (ITEM_ID, PARENT_ITEM_ID, ROOT_ITEM_ID, QUANTITY, LINE_ID)
    Values
    (17, 16, 10, 77, '1.1.1.1');
    Insert into XYZ
    (ITEM_ID, PARENT_ITEM_ID, ROOT_ITEM_ID, QUANTITY, LINE_ID)
    Values
    (31, 17, 10, 2, '1.1.1.1.1');
    Insert into XYZ
    (ITEM_ID, PARENT_ITEM_ID, ROOT_ITEM_ID, QUANTITY, LINE_ID)
    Values
    (33, 16, 10, 5, '1.1.1.2');
    Insert into XYZ
    (ITEM_ID, PARENT_ITEM_ID, ROOT_ITEM_ID, QUANTITY, LINE_ID)
    Values
    (32, 17, 10, 3, '1.1.1.1.2');
    Insert into XYZ
    (ITEM_ID, PARENT_ITEM_ID, ROOT_ITEM_ID, QUANTITY, LINE_ID)
    Values
    (14, 11, 11, 10, '1.2');
    Insert into XYZ
    (ITEM_ID, PARENT_ITEM_ID, ROOT_ITEM_ID, QUANTITY, LINE_ID)
    Values
    (13, 11, 11, 9, '1.1');
    Insert into XYZ
    (ITEM_ID, ROOT_ITEM_ID, QUANTITY, LINE_ID)
    Values
    (11, 11, 8, '1.0');
    Insert into XYZ
    (ITEM_ID, PARENT_ITEM_ID, ROOT_ITEM_ID, QUANTITY, LINE_ID)
    Values
    (23, 13, 11, 77, '1.1.1');
    Insert into XYZ
    (ITEM_ID, PARENT_ITEM_ID, ROOT_ITEM_ID, QUANTITY, LINE_ID)
    Values
    (49, 23, 11, 5, '1.1.1.1');
    Insert into XYZ
    (ITEM_ID, PARENT_ITEM_ID, ROOT_ITEM_ID, QUANTITY, LINE_ID)
    Values
    (16, 91, 14, 56, '1.1.2');
    Insert into XYZ
    (ITEM_ID, PARENT_ITEM_ID, ROOT_ITEM_ID, QUANTITY, LINE_ID)
    Values
    (92, 91, 14, 10, '1.1.1');
    Insert into XYZ
    (ITEM_ID, PARENT_ITEM_ID, ROOT_ITEM_ID, QUANTITY, LINE_ID)
    Values
    (91, 14, 14, 8, '1.1');
    Insert into XYZ
    (ITEM_ID, ROOT_ITEM_ID, QUANTITY, LINE_ID)
    Values
    (14, 14, 6, '1.0');
    Insert into XYZ
    (ITEM_ID, ROOT_ITEM_ID, QUANTITY, LINE_ID)
    Values
    (110, 110, 1, '1.0');
    Insert into XYZ
    (ITEM_ID, PARENT_ITEM_ID, ROOT_ITEM_ID, QUANTITY, LINE_ID)
    Values
    (17, 110, 110, 1, '1.2');
    Insert into XYZ
    (ITEM_ID, PARENT_ITEM_ID, ROOT_ITEM_ID, QUANTITY, LINE_ID)
    Values
    (111, 110, 110, 1, '1.1');
    COMMIT;
    The expected result for product with root_item_id as 14
    item_id hierarchy_path
    11 /11
    13 /11/13
    23 /11/13/23
    49 /11/13/23/49
    14 /11/14 -- it should explode the hierarchy of product with id 14
    91 /11/14/91 as there exists a configuration for this product as a root
    16 /11/14/91/16
    92 /11/14/91/92
    In above example, it should explode the hierarachy of other products too (item_id 13,23 etc) if there exists a product configuration (starting with root_item_id as 13 or 23 etc.) for them in the table.
    Thanks,
    - Ajit

  • DELETING child record of same table..  qry  required( complicated)

    hai
    how to delete the child record of same table...?
    Here is the example...
    CREATE TABLE TDA
    (     PKNODAVE VARCHAR2(7 BYTE) NOT NULL ENABLE,
         DTCREATION DATE,
         DAVETRANSFERT VARCHAR2(7 BYTE),
         PKPARC NUMBER(5,0)
    ALTER TABLE TDA ADD CONSTRAINT PK_TDAV8 PRIMARY KEY (PKNODAVE)
    ALTER TABLE TDA ADD CONSTRAINT FK_TDA1 FOREIGN KEY (DAVETRANSFERT)
         REFERENCES TDA (PKNODAVE) ENABLE
    REM INSERTING into TDA
    Insert into TDA (PKNODAVE,DTCREATION,DAVETRANSFERT,PKPARC) values ('1',to_date('05-JAN-10','DD-MON-RR'),'1',10);
    Insert into TDA (PKNODAVE,DTCREATION,DAVETRANSFERT,PKPARC) values ('2',to_date('05-JAN-10','DD-MON-RR'),'2',10);
    Insert into TDA (PKNODAVE,DTCREATION,DAVETRANSFERT,PKPARC) values ('3',to_date('05-JAN-10','DD-MON-RR'),'3',10);
    Insert into TDA (PKNODAVE,DTCREATION,DAVETRANSFERT,PKPARC) values ('4',to_date('05-JAN-10','DD-MON-RR'),null,10);
    Insert into TDA (PKNODAVE,DTCREATION,DAVETRANSFERT,PKPARC) values ('5',to_date('05-JAN-10','DD-MON-RR'),'4',14);
    Insert into TDA (PKNODAVE,DTCREATION,DAVETRANSFERT,PKPARC) values ('6',to_date('05-JAN-10','DD-MON-RR'),'5',15);
    DELETE FROM TDA WHERE davetransfert IN ( SELECT PKNODAVE FROM TDA WHERE PKPARC='10')
    ERROR: FK_TDA1 CHILD RECORD FOUND...
    Pls give me the suggestions to solve this
    S

    You could try with a recursive procedure like this
    Processing ...
    select *
    from TDA
    Query finished, retrieving results...
    PKNODAVE      DTCREATION    DAVETRANSFERT   PKPARC  
    1                   05/01/10 1                     10
    2                   05/01/10 2                     10
    3                   05/01/10 3                     10
    4                   05/01/10                       10
    5                   05/01/10 4                     14
    6                   05/01/10 5                     15
    6 row(s) retrieved
    Processing ...
    declare
         cursor c is
              SELECT PKNODAVE FROM TDA WHERE PKPARC='10';
         procedure tda_cascade_delete(
                   del_PKNODAVE in varchar2
         as
              cursor sons is
                   select PKNODAVE
                   from TDA
                   where DAVETRANSFERT = del_PKNODAVE
                        and PKNODAVE <> DAVETRANSFERT;
         begin
              for x in sons loop
                   tda_cascade_delete(x.PKNODAVE);
              end loop;
              delete TDA
              where PKNODAVE = del_PKNODAVE;
         end;
    begin
         for x in c loop
              tda_cascade_delete(x.PKNODAVE);
         end loop;
    end;
    Processing ...
    select *
    from TDA
    Query finished, retrieving results...
    PKNODAVE      DTCREATION    DAVETRANSFERT   PKPARC  
    0 row(s) retrievedPS. A connect by subquery of the type
    delete tab
    where pk in (
              select fk
              from tab
              start with <my condition>
                   connect by fk = prior pk
         ) or <my condition>l;wouldn't generally work because it could try to delete a record before its children.
    Bye Alessandro

  • Hierarchy query showing  parent and their child records

    I'm a newbie on Oracle using Tora,
    I'm Trying to run a query that will show me a hierarchical view of parent and child records in a table.
    So far I"ve found a query format like this, but its not working
    SELECT employee_id, last_name, manager_id
    FROM employees
    CONNECT BY PRIOR employee_id = manager_id;
    but when running it with my tables and columns I get an error message
    saying something 'cannont run CONNECT BY in subquery'
    Any ideas?

    Thanks for all the help, I'm getting the error message
    'ORA-01473: cannot have subqueries in CONNECT BY clause'
    Here's my actual query
    select           resource_id, lname, org_id
    from           std_resource
    start with      resource_id = 413783
         connect by prior resource_id = org_id;
    I'm trying to display a hierarchical list of user resource_id's, last names, and org_id's from the std_resource table starting withe resource_id 413783

  • Row wise insertion of Master - Child Record

    Hi,
    Please help me with below scenario:
    I have two tables Master - M and child - C
    M Contains M1, M2,
    C Contains M1 C1, M1 C2, M2 C3
    Currently the ODI inserts data of Table M and then it inserts data of C
    But I want the data to be inserted in the below given format
    1. M1 should be inserted
    2. Then C1, C2 to be inserted, if there is any error while inserting C2, ODI should rollback C2, C1 and also M1.
    3. Then it should start with next row of the Master table, and if there is no error while inserting the master and child record, then records M2 and C3 should be commited.
    Thanks in advance.
    Varma

    Hi Varma,
    I also need the steps for the same scenario. Cezar have given me some work arounds, which is working fine(row by row transformation) but we are facing some problem in commit and rollback. The steps are given in the below link.
    Commit Rollback for Parent & Child table
    Thanks in Advance,
    Ram Mohan T

  • Cannot sort child rows in multilevel tree table

    Hi,
    I originally hijacked a two-year-old forum thread that was vaguely similar to my issue, but a kind forum moderator split my post away
    (and deleted my other hijack post asking this same question)
    so that my inquiry might be viewable on its own.
    Hopefully someone can pay attention to my issue instead of getting it confused with those other old forum threads.
    So, here we go ...
    Is sorting in a treeTable at a particular level possible? Just want to let you I have tried the following approaches to do this. But it dis not work for me.
    I have tree table with 2 levels. I am trying to sort the child rows based on its column say "Display Sequence".
    User can type in number in this column which contains input text. On value change event of the this field, all the
    child rows in the level 2 need to be sorted. This needs to be done without committing the data. On commit it works,
    because it sorts based on order by clause. I want the child rows to be sorted on value change event. Following
    various approaches I tried.
    TreeModel tModel = (TreeModel)treeTable.getValue();
    SortCriterion sortCriterion = new SortCriterion("DisplaySequence",true);
    List<SortCriterion> sortCriteriaList = new ArrayList<SortCriterion>();
    sortCriteriaList.add(sortCriterion);
    tModel.setSortCriteria(sortCriteriaList);
    The above code does not work, As "DisplaySequence" is not available in the parent view object.
    Here is approach no 2
    JUCtrlHierBinding treeTableBinding = null;
    JUCtrlHierNodeBinding nodeBinding = null;
    JUCtrlHierNodeBinding parentNodeBinding = null;
    JUCtrlHierTypeBinding nodeHierTypeBinding = null;
    Key rowKey;
    Object dispSeqObj;
    Number displaySequence = null;
    Map<Key,Number> keyValueMap = null;
    Set<Key> emptyValueKeySet = null;
    Map<Key,Number> sortedKeyValueMap = null;
    DCIteratorBinding target = null;
    Iterator iter = null;
    int rowIndex = 1;
    RowSetIterator rsi = null;
    Row currentRow = null;
    Row row = null;
    RowKeySet selectedRowKey = lookupTreeTable.getSelectedRowKeys();
    Iterator rksIterator = selectedRowKey.iterator();
    if (rksIterator.hasNext()) {
    List key = (List)rksIterator.next();
    System.out.println("key :"+key);
    treeTableBinding = (JUCtrlHierBinding) ((CollectionModel)lookupTreeTable.getValue()).getWrappedData();
    nodeBinding = treeTableBinding.findNodeByKeyPath(key);
    parentNodeBinding = nodeBinding.getParent();
    //rsi = nodeBinding.getParentRowSetIterator();
    rsi = parentNodeBinding.getChildIteratorBinding().getRowSetIterator();
    keyValueMap = new LinkedHashMap<Key,Number>();
    emptyValueKeySet = new LinkedHashSet<Key>();
    // Gets the DisplaySequence by iterating through the child rows
    while(rsi.hasNext()) {
    if(rowIndex==1)
    row = rsi.first();
    else
    row = rsi.next();
    rowKey = row.getKey();
    dispSeqObj = row.getAttribute("DisplaySequence");
    if(dispSeqObj!=null && dispSeqObj instanceof Number) {
    displaySequence = (Number)dispSeqObj;
    keyValueMap.put(rowKey, displaySequence);
    }else {
    emptyValueKeySet.add(rowKey);
    rowIndex++;
    rowIndex = 0;
    // Sort the numbers using comparator
    DisplaySequenceComparator dispSeqComparator = new DisplaySequenceComparator(keyValueMap);
    sortedKeyValueMap = new TreeMap<Key,Number>(dispSeqComparator);
    sortedKeyValueMap.putAll(keyValueMap);
    rsi.reset();
    nodeHierTypeBinding = nodeBinding.getHierTypeBinding();
    System.out.println("nodeHierTypeBinding :"+nodeHierTypeBinding);
    String expr = nodeHierTypeBinding.getTargetIterator();
    if (expr != null) {
    Object val = nodeBinding.getBindingContainer().evaluateParameter(expr, false);
    if (val instanceof DCIteratorBinding) {
    target = ((DCIteratorBinding)val);
    ViewObject targetVo = target.getViewObject();
    System.out.println("targetVo :"+targetVo);
    targetVo.setAssociationConsistent(true);
    //ri = target.findRowsByKeyValues(new Key[]{rowData.getRowKey()});
    rsi = parentNodeBinding.getChildIteratorBinding().getRowSetIterator();
    //rsi = nodeBinding.getParentRowSetIterator();
    // Rearrange the tree rows by inserting at respective index based on sorting.
    ViewObject vo = nodeBinding.getViewObject();
    iter = sortedKeyValueMap.keySet().iterator();
    while(iter.hasNext()) {
    currentRow = rsi.getRow((Key)iter.next());
    rsi.setCurrentRow(currentRow);
    rsi.setCurrentRowAtRangeIndex(rowIndex);
    //rsi.insertRowAtRangeIndex(rowIndex, currentRow);
    rowIndex++;
    iter = emptyValueKeySet.iterator();
    while(iter.hasNext()) {
    currentRow = rsi.getRow((Key)iter.next());
    rsi.setCurrentRow(currentRow);
    rsi.setCurrentRowAtRangeIndex(rowIndex);
    //rsi.insertRowAtRangeIndex(rowIndex, currentRow);
    rowIndex++;
    rsi.closeRowSetIterator();
    AdfFacesContext.getCurrentInstance().addPartialTarget(treeTable);
    private class DisplaySequenceComparator implements Comparator {
    Map<Key,oracle.jbo.domain.Number> dispSeqMap = null;
    public DisplaySequenceComparator(Map<Key,oracle.jbo.domain.Number> dispSeqMap) {
    this.dispSeqMap = dispSeqMap;
    public int compare(Object a, Object b) {
    Key key1 = (Key)a;
    Key key2 = (Key)b;
    oracle.jbo.domain.Number value1 = dispSeqMap.get(key1);
    oracle.jbo.domain.Number value2 = dispSeqMap.get(key2);
    if(value1.getValue() > value2.getValue()) {
    return 1;
    } else if(value1.getValue() == value2.getValue()) {
    return 0;
    } else {
    return -1;
    In the above code I tried to perform sorting of DisplaySequence values using comparator, then tried to rearrange
    nodes or rows based on sort resurts. But rsi.insertRowAtRangeIndex(rowIndex, currentRow) give
    DeadViewException...unable to find view reference. While setting current row also does not work.
    Approach 3.
    DCIteratorBinding iter1 =
    bindings.findIteratorBinding("childIterator");
    iter1.executeQuery();
    SortCriteria sc = new SortCriteriaImpl("DisplaySequence",false);
    SortCriteria [] scArray = new SortCriteria[1];
    scArray[0] = sc;
    iter1.applySortCriteria(scArray);
    Any help in Sorting Child nodes ADF treeTable is appreciated. Thanks in Advance.
    Abhishek

    Hi Frank,
    Thanks for your reply. I have tried similar approach for sorting tree table child rows based on user specified number and it works. But there is a limitation for this. This sorting works only for read only/transient view object. For updatable view object after sorting, data cannot be saved or updated, as it cannot find the rowid. Here is what I tried
    In the ParentViewImpl class,
    1. overrode the method createViewLinkAccessorRS, so that this method is forcefully executed.
    @Override
    protected ViewRowSetImpl createViewLinkAccessorRS(AssociationDefImpl associationDefImpl,
    oracle.jbo.server.ViewObjectImpl viewObjectImpl,
    Row row,
    Object[] object) {
    ViewRowSetImpl viewRowSetImpl = super.createViewLinkAccessorRS(associationDefImpl, viewObjectImpl, row, object);
    return viewRowSetImpl;
    2. Added the following method, which will be invoked on valueChange of DisplaySequence in child row. Expose this method through client interface. This method accept a parameter i.e. parent row key of the child row.
    public void sortChildRecords(Key parentKey) {
    ViewObject viewObject = null;
    String type = null;
    if(parentKey==null) {
    Row [] row = this.findByKey(parentKey, 1);
    RowSet rowSet = (RowSet)row[0].getAttribute("ChildVO");
    viewObject = rowSet.getViewObject();
    viewObject.setSortBy("DisplaySequence asc");
    }else {
    Row row = getCurrentRow();
    RowSet rowSet = (RowSet)row.getAttribute("ChildVO");
    viewObject = rowSet.getViewObject();
    viewObject.setSortBy("DisplaySequence asc");
    this.setQueryMode(ViewObject.QUERY_MODE_SCAN_DATABASE_TABLES |
    ViewObject.QUERY_MODE_SCAN_ENTITY_ROWS);
    this.executeQuery();
    For custom sort, lets say all the numbers should be display first in ascending order, and null or empty values to be display at the end need to override the getRowComparator method in the ChildViewImpl class,
    Here is the code for the same
    @Override
    public Comparator getRowComparator() {
    SortCriteria sortCriteria = new SortCriteriaImpl("DisplaySequence",false);
    SortCriteria [] sortCriterias = new SortCriteria[1];
    sortCriterias[0] = sortCriteria;
    return new DisplaySequenceComparator(sortCriterias);
    private class DisplaySequenceComparator extends RowComparator {
    public DisplaySequenceComparator(SortCriteria [] sortCriterias) {
    super(sortCriterias);
    public int compareRows(Row row1, Row row2) {
    Object dispSeqObj1;
    Object dispSeqObj2;
    Number dispSeq1 = null;
    Number dispSeq2 = null;
    boolean compareRow1 = true;
    boolean compareRow2 = true;
    if(row1!=null) {
    dispSeqObj1 = row1.getAttribute("DisplaySequence");
    if(dispSeqObj1!=null && dispSeqObj1 instanceof Number) {
    dispSeq1 = (Number)dispSeqObj1;
    }else {
    compareRow1 = false;
    if(row2!=null) {
    dispSeqObj2 = row2.getAttribute("DisplaySequence");
    if(dispSeqObj2!=null && dispSeqObj2 instanceof Number) {
    dispSeq2 = (Number)dispSeqObj2;
    }else {
    compareRow2 = false;
    if(compareRow1 && compareRow2) {
    if(dispSeq1.getValue() > dispSeq2.getValue()) {
    return 1;
    } else if(dispSeq1.getValue() == dispSeq2.getValue()) {
    return 0;
    } else {
    return -1;
    if(!compareRow1 && compareRow2)
    return 1;
    if(compareRow1 && !compareRow2)
    return -1;
    return 0;
    The above solution works properly, and sorts the child tree rows. But while saving the changes, update fails. I also came to know that in-memory sorting is applicable to read-only/transient view objects from some blogs and also mentiond in this link http://docs.oracle.com/cd/E24382_01/web.1112/e16182/bcadvvo.htm
    Is there any way that updatable view objects can be sorted and saved as well?
    Thanks,
    Abhishek
    Edited by: 930857 on May 2, 2012 7:12 AM

  • Open dialog box window with checkboxes for each child record - Please Help

    Hello Everybody
    I have a 10g form with master record and 20 child records. In the child record form, currently there is a “Notes” Editor, which pops up when user click the “Edit” button. In the “Notes” editor, user enters remarks if anything is missing. For example, typical remarks will be: Statement is missing, LOC paper is missing etc.
    Now, I would like to replace “Notes” editor with a dialog box. In the dialog box , I would like to add checkboxes with values “Statement is missing” and “LOC paper is missing” etc. along with “Notes” field. The user can select checkboxes. The value of the checkboxes should go in the “Notes” field with the ability to edit it. This way, user doesn’t need to type the most common notes every time.
    I have created a “NewNotes” dialog box with checkboxes and multiline text Item. It is pops up when I click on the button. I have also created to WHEN_CHECKBOC_CHANGED trigger for each checkboxes so that the its value will go in a multiline text item.
    But, I am not sure how I can link “NewNotes” dialog box to the each record in child record block. I would really appreciate it if anybody could give me some idea.
    Thanks,

    if i understand correctly you have a note item (based on table) on every child record? when you open the dialog box: how do you put data from notes to dialog box? in the same way as you can write it back ...

  • How to create Child record at the time of master record creation.

    Hi,
    I have MasterVO and ChildVO. And association between both are 1 to *. I have a requirement like, I need to create row in ChildVO at the time of MasterVO row creation.
    I have used entity based association to create view link. This view link created ChildVO accessor in MasterRowImpl as type RowIterator.
    Actually my idea is to override create method in MasterVORowImpl and call ChildVO ViewObject and call .createRow() method on it. But I don't have access to ViewObject, instead it gave access to RowIterator.
    Could you please provide any pointer to achieve above functionality?
    Many thanks in advance.
    Jdev version - 11.1.1.7.0
    Regards,
    Dileep.

    Hi Tim,
    Now it is creating child record at the time of master row creation. But it is working only through BC tester. But when I drag the child VO instance in the jsff page, only master is get created as editable only, child is displayed as read only without populating any default values like child VO surrogate key and other default attributes. But through BC tester it is working fine.
    Am I missing anything here while implementing in UI?
    Thanks,
    Dileep.

Maybe you are looking for