Find child record of a parent record

Hi,
I need to find the child recond of a parent party and if that child also have some
child then I need to find again and this process will go untill no child record
found(child is null)
I am trying to do it by the help of hierarchical query.
can anyone please help and tell me how can I do that and how can I handle if a parent have multiple childs.
Mohan

It is always helpful to provide the following:
1. Oracle version (SELECT * FROM V$VERSION)
2. Sample data in the form of CREATE / INSERT statements.
3. Expected output
4. Explanation of expected output (A.K.A. "business logic")
5. Use \ tags for #2 and #3. See FAQ (Link on top right side) for details.
Also see the third post in this thread:
{thread:id=2174552}
This would probably be better suited in the {forum:id=75} forum.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

Similar Messages

  • How to find child records is exists before to delete parent records.

    Dear Everyone,
    I would like to ask you, is there any simple way to find child records is exists before to delete parent records.
    I have a master table defined primary key and I have referenced that as foreign key in many tables.
    I have used Delete_Record to delete but it isn't display the message 'child record exist' but it cleared the record from the form. So I need to know how to find child records is exists or not before to do delete_record so that I can display message in-case it exists.
    I do know we can able to check in every table matching the column manually, but what if we use 100 of tables then it is not possible to check manually.
    I am sure there must be simple way to find as how the oracle identifies when we execute delete query.
    Please help me on this.
    Thanks in advance.

    Simple solution is to run the query I have given for all child tables or to try a single query for all child tables withj something like:
    select <parent_key>
    from <parent_table>
    where <parent_key> in
              (select <foreign_key_1> from <child_table_1> union
               select <foreign_key_2> from <child_table_2> union
               ... );More complicate solution could be to change the foreign key constraints to cascade DELETE on parent table to child tables:
    SQL>
    SQL> create table p(x int primary key);
    Table created.
    SQL> create table c1(x1 int);
    Table created.
    SQL> create table c2(x2 int);
    Table created.
    SQL>
    SQL> alter table c1 add constraint fk1 foreign key(x1) references p;
    Table altered.
    SQL> alter table c2 add constraint fk2 foreign key (x2) references p;
    Table altered.
    SQL>
    SQL>
    SQL> insert into p values(1);
    1 row created.
    SQL> insert into c1 values(1);
    1 row created.
    SQL> insert into c2 values(1);
    1 row created.
    SQL> commit;
    Commit complete.
    SQL>
    SQL> alter table c1 drop constraint fk1;
    Table altered.
    SQL> alter table c2 drop constraint fk2;
    Table altered.
    SQL>
    SQL> alter table c1 add constraint fk1 foreign key(x1) references p on delete cascade;
    Table altered.
    SQL> alter table c2 add constraint fk2 foreign key (x2) references p on delete cascade;
    Table altered.
    SQL>
    SQL> delete p where x=1;
    1 row deleted.
    SQL> commit;
    Commit complete.
    SQL> select * from p;
    no rows selected
    SQL> select * from c1;
    no rows selected
    SQL> select * from c2;
    no rows selected
    SQL>Edited by: P. Forstmann on 27 oct. 2011 14:01

  • How to find child records given a parent key

    I have a master table which is parent for several child tables. I want to display a button to delete a record in master table. I would prefer show this button conditionally so when a master record has child records, I don't show delete button and no error is raised.
    Of course I could scan every child table to find out child records, but I think must exist a generic method
    How can I find out if a given parent key has child records?
    Thanks in advance
    Oscar
    P.S: I'm using 10gR2
    Edited by: user10712087 on 13/01/2009 02:31 PM

    Oscar
    There's no magic/generic way to check that a master row has no associated detail rows. As Pavan says, you have to decide which detail tables to check, and check them using SQL as usual. (Actually, there is a quick way - you delete the row and if there are any child rows with foreign keys that don't cascade, the delete will fail; but of course you can't use this in case the delete succeeds but the user never wants to press the button).
    One addition to Pavan's answer: DO NOT under any circumstances count all the records in every detail table. All you want to know is, is there at least 1 detail record in at least 1 of the tables. No need to count 100 or 1000 rows...
    You can do this like this in your PL/SQL
    FUNCTION check_children(p_master_id IN INTEGER) RETURN BOOLEAN
    IS
      CURSOR c_child1  IS
      select 1 from child_table_1 where master_id = check_children.p_master_id;
      CURSOR c_child2 IS
      select 1 from child_table_2 where master_id = check_children.p_master_id;
      -- etc for all child tables
    l_rec_present integer := null;
    BEGIN
        OPEN c_child_1;
        FETCH c_child_1 INTO l_rec_present;
        CLOSE c_child_1;
        IF l_rec_present i= 1 THEN
            -- there is a child in child_table_1
            RETURN TRUE;
        END IF;
        OPEN c_child_2;
        FETCH c_child_2 INTO l_rec_present;
        CLOSE c_child_2;
        IF l_rec_present i= 1 THEN
            RETURN TRUE;
        END IF;
    -- etc for each child; finally, if no child found:
       RETURN FALSE;
    END;This makes sure that (1) you stop as soon as you find any child, and (2) you don't get any NO_DATA_FOUND or TOO_MANY_ROWS exceptions raised.
    HTH
    Regards Nigel

  • 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.

  • 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.

  • 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

  • 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.

  • Inserting parent /child records from a xml file ...

    XML file pasted below:
    I have loaded the xml file into a table called xml_demo which has a column xml_data of type xmltype.
    The select for parent record is as follows and it works:
    INSERT INTO balit_submissions (balitdoc, documentversion, datetime_from,job_id, status,creation_datetime)
    (SELECT 'MOL'
    ,to_number(extract(x.xml_data,'/MolDocument/DocumentVersion/@v'))
    ,to_date(substr(extract(x.xml_data,'/MolDocument/ValidTimeInterval/@v'),1,16),
    'yyyy-mm-dd"T"hh24:mi')
    ,123456
    ,'CREATED',
    NULL
    FROM xml_DEMO x WHERE
    existsnode(x.xml_data,'/MolDocument/DocumentIdentification[@v="MOL_20100331_1500_1600"]') = 1)
    Having problem creating child records. From this file I expect to create 3 records.
    insert into balit_energy_blocks
    SO_ID,
    DATETIME_FROM,
    DIRECTION,
    BLOCK_NUMBER,
    ENERGY,
    LAST_SUBMIT_DATETIME,
    PRICE_POUNDS,
    PRICE_EUROS,
    BALIT_REF,
    STATUS,
    LAST_EDIT_DATETIME,
    MOL_REASON,
    ACQUIRING_SO_AREA)
    (SELECT 'RTE'
    ,to_date(substr(extract(x.xml_data,'/MolDocument/ValidTimeInterval/@v'),1,16),
    'yyyy-mm-dd"T"hh24:mi')
    ,DECODE(extract(x.xml_data,'/MolDocument/MolTimeSeries/Direction/@v'),'AO1','Up','Down')
    ,to_number(substr(extract(x.xml_data,'/MolDocument/MolTimeSeries/ContractIdentification/@v'),19))
    ,to_number(extract(x.xml_data,'/MolDocument/MolTimeSeries/Period/Interval/EnergyPrice/@v'))
    ,sysdate
    ,null -- price pounds
    ,null -- price euro
    ,extract(x.xml_data,'/MolDocument/MolTimeSeries/ContractIdentification/@v')
    ,'SUBMITTED'
    ,'A96'
    ,NULL -- acquiring area
    ,sysdate
    FROM xml_DEMO x WHERE
    existsnode(x.xml_data,'/MolDocument/DocumentIdentification[@v="MOL_20100331_1500_1600"]') = 1)
    For example, there are 3 ContractIdentification tags. Example of 1:
    <ContractIdentification v="RTE_20100331_1500_16"/>
    I was expecting this select to pluck the last number from this string. In this case 16.
    The select was:
    to_number(substr(extract(x.xml_data,'/MolDocument/MolTimeSeries/ContractIdentification/@v'),19))
    The result I got was:
    16RTE_20100331_1500_20NG_20100331_1500_6
    All contractident values are concatnated and returns from position 19 onwards.
    Can anyone help me to extract the last number from each ContractIdentification tag value and to create the 3 records
    Thanks
    James Sathiaraj
    <?xml version="1.0" encoding="UTF-8"?>
    <MolDocument DtdVersion="3" DtdRelease="0">
    <DocumentIdentification v="MOL_20100331_1500_1600"/>
    <DocumentVersion v="1"/>
    <DocumentType v="A43"/>
    <SenderIdentification codingScheme="A01" v="17X100Z100Z0001H"/>
    <SenderRole v="A35"/>
    <ReceiverIdentification codingScheme="A01" v="10XFR-RTE------Q"/>
    <ReceiverRole v="A04"/>
    <CreationDateTime v="2010-03-31T14:10:00Z"/>
    <ValidTimeInterval v="2010-03-31T15:00Z/2010-03-31T16:00Z"/>
    <Domain codingScheme="A01" v="10YDOM-1001A001A"/>
    <MolTimeSeries>
    <ContractIdentification v="RTE_20100331_1500_16"/>
    <ResourceProvider codingScheme="A01" v="10XFR-RTE------Q"/>
    <AcquiringArea codingScheme="A01" v="17Y100Z100Z00013"/>
    <ConnectingArea codingScheme="A01" v="10YFR-RTE------C"/>
    <AuctionIdentification v="AUCTION_20100331_1500_1600"/>
    <BusinessType v="A10"/>
    <BidTimeInterval v="2010-03-31T15:00Z/2010-03-31T16:00Z"/>
    <MeasureUnitQuantity v="MAW"/>
    <Currency v="EUR"/>
    <MeasureUnitPrice v="MWH"/>
    <Direction v="A02"/>
    <MinimumActivationQuantity v="50"/>
    <Status v="A06"/>
    <Period>
    <TimeInterval v="2010-03-31T15:00Z/2010-03-31T16:00Z"/>
    <Resolution v="PT60M"/>
    <Interval>
    <Pos v="1"/>
    <Qty v="50"/>
    <EnergyPrice v="50.45"/>
    </Interval>
    </Period>
    </MolTimeSeries>
    <MolTimeSeries>
    <ContractIdentification v="RTE_20100331_1500_20"/>
    <ResourceProvider codingScheme="A01" v="10XFR-RTE------Q"/>
    <AcquiringArea codingScheme="A01" v="17Y100Z100Z00013"/>
    <ConnectingArea codingScheme="A01" v="10YFR-RTE------C"/>
    <AuctionIdentification v="AUCTION_20100331_1500_1600"/>
    <BusinessType v="A10"/>
    <BidTimeInterval v="2010-03-31T15:00Z/2010-03-31T16:00Z"/>
    <MeasureUnitQuantity v="MAW"/>
    <Currency v="EUR"/>
    <MeasureUnitPrice v="MWH"/>
    <Direction v="A02"/>
    <MinimumActivationQuantity v="50"/>
    <Status v="A06"/>
    <Period>
    <TimeInterval v="2010-03-31T15:00Z/2010-03-31T16:00Z"/>
    <Resolution v="PT60M"/>
    <Interval>
    <Pos v="1"/>
    <Qty v="50"/>
    <EnergyPrice v="50.48"/>
    </Interval>
    </Period>
    </MolTimeSeries>
    <MolTimeSeries>
    <ContractIdentification v="NG_20100331_1500_6"/>
    <ResourceProvider codingScheme="A01" v="10X1001A1001A515"/>
    <AcquiringArea codingScheme="A01" v="17Y100Z100Z00013"/>
    <ConnectingArea codingScheme="A01" v="10YGB----------A"/>
    <AuctionIdentification v="AUCTION_20100331_1500_1600"/>
    <BusinessType v="A10"/>
    <BidTimeInterval v="2010-03-31T15:00Z/2010-03-31T16:00Z"/>
    <MeasureUnitQuantity v="MAW"/>
    <Currency v="EUR"/>
    <MeasureUnitPrice v="MWH"/>
    <Direction v="A01"/>
    <MinimumActivationQuantity v="50"/>
    <Status v="A06"/>
    <Period>
    <TimeInterval v="2010-03-31T15:00Z/2010-03-31T16:00Z"/>
    <Resolution v="PT60M"/>
    <Interval>
    <Pos v="1"/>
    <Qty v="50"/>
    <EnergyPrice v="17.0"/>
    </Interval>
    </Period>
    </MolTimeSeries>
    </MolDocument>

    Hi,
    The result I got was:
    16RTE_20100331_1500_20NG_20100331_1500_6In the query you tried, you access a single record so you can't expect to get three rows "magically". The EXTRACT function just works as expected, it extracts the requested nodes, but the result is still an XML fragment (a scalar value).
    In order to achieve your goal, you have to break the MolTimeSeries sequence into relational rows.
    Two similar solutions are possible, XMLTable (10gR2 and up) or Table/XMLSequence.
    In your other post you mentioned db version 10.1, so I guess we'll go with XMLSequence :
    SELECT 'RTE'
           ,to_date(substr(extractvalue(x.xml_data,'/MolDocument/ValidTimeInterval/@v'),1,16),'yyyy-mm-dd"T"hh24:mi')
           ,decode(extractvalue(x2.column_value,'/MolTimeSeries/Direction/@v'),'A01','Up','Down')
           ,to_number(regexp_substr(extractvalue(x2.column_value,'/MolTimeSeries/ContractIdentification/@v'),'\d+$'))
           ,to_number(extractvalue(x2.column_value,'/MolTimeSeries/Period/Interval/EnergyPrice/@v'))
           ,sysdate
           ,null
           ,null
           ,extractvalue(x2.column_value,'/MolTimeSeries/ContractIdentification/@v')
           ,'SUBMITTED'
           ,'A96'
           ,null
           ,sysdate
    FROM xml_demo x,
         table(
           xmlsequence(
             extract(x.xml_data, '/MolDocument/MolTimeSeries')
         ) x2
    WHERE existsnode(x.xml_data,'/MolDocument/DocumentIdentification[@v="MOL_20100331_1500_1600"]') = 1;Please also note the use of REGEXP_SUBSTR instead of the regular SUBSTR because it didn't work for "NG_20100331_1500_6".
    Hope that helps.
    Edited by: odie_63 on 24 juin 2010 21:18 - added regexp comment

  • How to update child record when item from parent record changes

    Hi, I have a master and detail form with two regions on the same page.
    Region one references parent record, one of column in the parent record is also in the child record. And is one to many relation
    between parent record and child record. How can I have the column on the child record updated when the column of the parent record is being modified?
    For exemple; Parent record has two columns : ID and Program.
    Child record has Program, goal# and status. I have two pages established, page 27 and page 28.
    Page 27 list out all programs from parent record, by clicking on edit to a program, it braches to page 28 with program listed as editable field in region one, and mulitple records list in region two from the child record with the same program.
    The problem that I am having is once the program in region one got modified using ApplyMRU, the program in child record did not get updated with the new value and therefore those record become orphan records. I need a way to update all current child records with the new program value.
    Thanks in advance for anyone who can hlep out on this problem.
    Julie
    Edited by: JulieHP on May 24, 2012 4:57 PM

    One Idea is
    If possible create a after update database trigger on the parent table to update the relevant child record.
    Next one
    Create a PL/SQL process on the parent page with process sequence next to ApplyMRU, so when the ApplyMRU is seccessfull it goes not to your process where you can have your update statement

  • How to obtain parent record from child record in relationship using API

    Hi,
    I have a record in the main table that is the child in a parent/child relationship to another main table record.  Using the Java API, how would I obtain the parent record in the relationship where I am starting with the child record?  In the API there seems to just be calls for getChildren, but not a getParent type call.
    Appreciate any immediate help that can be provided.
    Thanks,
    Eddie

    Hi Eddie,
    Please follow the below steps to retrieve only parents of a child Record.
    1. Create RetrieveRelationshipsCommand.
    2. Set the parameter RelationshipId.
    3. Set the parameter Anchor Record and Anchor Record Id. In this case the child record for which parents records to be retrieved.
    4. Set the parameter setGetChildren as false . This retrieves only the parent records for the specified child reocrd.
    5. Execute the RetrieveRelationshipsCommand.
    6. Retrieve member records from above step.
    Hope it helps
    Regards,
    Neeharika

  • ADF,how to delete parent record and related child record without manual cod

    Hi All,
    I'm using 11g adf.
    I have one parent table PAR and two child table CHD1 , CHD2 respectively.
    I'm inserting values in three tables , making a form having add , delete and edit buttons.
    Issue when i want to delete a record from PAR table , it gives child table record exists . i have did manual coding to delete the child records with related to the selected parent table PAR.
    Is there any process in ADF to delete the child records with respective selected parent record with out manual coding.
    thanks in advance.

    http://download.oracle.com/docs/cd/E14571_01/web.1111/b31974/bcentities.htm#BABHFJFJ
    John

  • How to delete parent table data even though it has child records

    hi all,
    How to delete parent table data even though it has child records.
    ex: delete from pa_request cascade constraints;
    But this command is not working .
    Regards,
    P Prakash

    833560 wrote:
    ex: delete from pa_request cascade constraints;cascade constraints is DROP table option. It can't be used with DELETE. You need to delete child rows first or drop foreign keys and recreate them with ON DELETE CASCADE. Then:
    delete from pa_request will automatically delete child rows. However, personally I don't like ON DELETE CASCADE. You can, by mistake, delete half of your database without even realizing it.
    SY.

  • How to delete parent and child records?

    Hi friends,
    I have a Master table and a child table.
    The Child table got reference key with the master table without on delete cascade.
    Now, I want to delete the Master records and also it's corresponding child records.
    How to do?
    Thanks in adv,
    regards,
    Vijay

    Delete the records from the child, then delete the records from the parent in two separate delete statements. I'd prefer that you create a stored procedure that does both steps.
    Justin

  • Insert child record when user commit parent data

    Hi everybody,
    My use case is an admin users page, where users add new users to application. So they specify user_name, last_name, .....
    I'd need to insert in a child record whose FK is user_name which was introduced by user in the parent table, just in the commit stage.
    How can I achive it? I'm user Jdev 12.1.2
    Regards,
    Jose.

    well leave that example...
    How you commiting the first row.. are using commit operation.Commit in bean using java code like this.
    public static OperationBinding findOperation(String operationName) {
       OperationBinding op = getDCBindingContainer().getOperationBinding("Commit");
       if (op == null) {
          throw new RuntimeException("Operation '" + operationName +"' not found");
       return op;
    . and after this you can get instance of vo of second VO. then create row
    ViewObjectImpl demo1 = am.getEmployeesDemo1();
           Row r2 = demo1.createRow();         // Creates a row in ViewObject
           r2.setAttribute("EmployeeId", 001); // you can set all values
           demo1.insertRow(r2);                //Insert that row in ViewObject
           am.getDBTransaction().commit();     //Commit the changes
           demo1.executeQuery();

  • Updating parent record owner to top 1 child record owner?

    I am trying to understand how to update a parent record's owner field to the value of a child record's owner field, but while there is only ever one parent record, there are multiple children, and I want to update the parent owner value to the owner
    of the first child record ever created for said parent.
    So for example, if the first child record created was owned by Joe Smith and the second child record created was owned by Betty Boop, I want to update the parent record to being owned by Joe Smith since he was the owner of the original child record.
    Key fields are Parent.ID, Child.ID, Parent.Owner, Child.Owner, Child.DateCreated. Hope that makes sense! It seems like using top 1 would be needed but I'm not entirely sure how to use it correctly with an update statement. I am generally pulling data not
    updating it, so I'm a bit out of my element.
    Thanks,
    Shaunna

    UPDATE t2
    SET Owner = t1.Owner
    FROM Parent t2
    INNER JOIN Child t1
    ON t2.ID = t1.ParentID
    WHERE NOT EXISTS
    SELECT 1
    FROM Child
    WHERE ParentID = t1.ParentID
    AND DateCreated < t1.DateCreated
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My Wiki User Page
    My MSDN Page
    My Personal Blog
    My Facebook Page

Maybe you are looking for

  • I have been charged twice for a service. Whom do I call?

    I have been charged twice for a service. Whom do I call?

  • Stuck in gray screen

    Im stuck in gray screen at startup with a spinning gear. Dont have a os disk, worried because i have tons of pics that are not backed up. :"O(

  • Mrp related problem

    Dear Gurus I am running mrp in md01 for consumption based planning.I have kept vb in mrp type hb in lot size and given the maximum stock limit  as well as reorder point.As I am running the mrp in md01 suppose a purchase requisition came for 100 for a

  • Desskjet 850c driver for windows 7 32 bit

    Hello folks Does anybody have a link for a deskjet 850c driver for windows 7, 32-bit,if there is one out there,I don't really want to replace this printer as it has been excellent!

  • Three level pop up

    Hi All, I want to have three level pop up menu on my application. First Level- Horizontal on mouseHover it should show next level vertical and on second level mouseHover it should again be Vertical. I have changed the required paramaters but its stil