XML parent child records

Hello
I am trying to mimic the FOR XML EXPLICIT behavior of SQL Server code in Oracle 11g.
The XML EXPILICT mode transforms the rowset that results from the query execution into an XML document and it preserves the parent child relationship in the XML output. For example
SELECT customer.id,customer.name,order.id,order.date,orderdetail.id,orderdetail.pid
FROM CUSTOMER,ORDER,ORDERDETAIL
WHERE CUSTOMER.ORDERID=ORDER.ORDERID
AND
ORDER.ORDERID=ORDERDETAIL.ORDERID
<Customer ID="C1" name="Ann">
<Order id="O1" date="1/20/2008">
<OrderDetail id="OD1" pid="P1"/>
<OrderDetail id="OD2" pid="P2"/>
</Order>
<Order id="O2" date="3/29/1997">
</Customer>
<Customer ID="C2" name="Jack">
<Order id="O1" date="1/20/2009">
<OrderDetail id="OF1" pid="P1"/>
<OrderDetail id="OF2" pid="P2"/>
</Order>
<Order id="O2" date="3/29/1997">
<OrderDetail id="OX1" pid="D1"/>
<OrderDetail id="OX2" pid="D2"/>
</Order>
</Customer>
Appreciate if you can help me to write an Oracle equivalent of this code.
Thanks & Regards

You can use xmlelement and xmlagg functions this way:
SQL> with customer as (
  2  select 'C1' id, 'Ann' name from dual union
  3  select 'C2' id, 'Jack' name from dual),
  4  Orders as (
  5  Select 'O1' id, '1/20/2008' odate, 'C1' custid from dual union
  6  Select 'O2' id, '3/29/1997' odate, 'C1' custid from dual union
  7  Select 'O3' id, '1/20/2008' odate, 'C2' custid from dual union
  8  Select 'O4' id, '3/29/1997' odate, 'C2' custid from dual),
  9  orderdetail as (
10  select 'OD1' id, 'P1' pid, 'O1' orderid from dual union
11  select 'OD2' id, 'P2' pid, 'O1' orderid from dual union
12  select 'OF1' id, 'P1' pid, 'O3' orderid from dual union
13  select 'OF2' id, 'P2' pid, 'O3' orderid from dual union
14  select 'OX1' id, 'D1' pid, 'O4' orderid from dual union
15  select 'OX2' id, 'D2' pid, 'O4' orderid from dual
16  )
17  -- End of test data, actual query follows
18  SELECT xmlagg(
19           xmlelement("Customer",
20                      xmlattributes(id, name),
21                      (select xmlagg(
22                                xmlelement("Order",
23                                           xmlattributes(o.id, o.odate as "date"),
24                                           (select xmlagg(
25                                                     xmlelement("OrderDetail",
26                                                                xmlattributes(id,pid),
27                                                                null
28                                                                )
29                                                          )
30                                              from orderdetail d
31                                             where d.orderid = o.id
32                                            )
33                                           )
34                                     )
35                         from orders o
36                        where CUSTOMER.ID=O.CUSTID
37                       )
38                      )
39                 ).extract('/*') xml
40    from customer;
XML
<Customer ID="C1" NAME="Ann">
  <Order ID="O1" date="1/20/2008">
    <OrderDetail ID="OD1" PID="P1"/>
    <OrderDetail ID="OD2" PID="P2"/>
  </Order>
  <Order ID="O2" date="3/29/1997"/>
</Customer>
<Customer ID="C2" NAME="Jack">
  <Order ID="O3" date="1/20/2008">
    <OrderDetail ID="OF1" PID="P1"/>
    <OrderDetail ID="OF2" PID="P2"/>
  </Order>
  <Order ID="O4" date="3/29/1997">
    <OrderDetail ID="OX1" PID="D1"/>
    <OrderDetail ID="OX2" PID="D2"/>
  </Order>
</Customer>Max
[My Italian Oracle blog|http://oracleitalia.wordpress.com/2010/02/07/aggiornare-una-tabella-con-listruzione-merge/]

Similar Messages

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

  • 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 achieve parent - child record insert in forms

    Guys,
    I am new to forms. I do have a requirement where I need to create one tabular block for 10 rows (parent record) and then I need to create three tabular tabs of 5 rows for detailed records (child). That means each tab can have 5 records for 1 parent row.. Thats how this parent-child structure has ONE to MANY relationships
    To achieve this requirement I created one parent block of table type (using table XX_Parent) and then I created three detailed block for each tab (Tab_A,Tab_B,Tab_C) using child table (XX_Child). For each tab while inserting the data I took one context_value column in child table. i.e. when I insert the data using Tab_A , context_value column will be A. In the same way B and C for Tab_B for Tab_C respectively. And I wrote this logic at PRE-INSERT trigger for each tab. But when I insert the data for all the tabs, it allows me to enter successfully for Tab_A only, the moment I navigate from Tab_A to enter the data intoTab_B, it throws me error like "You are passing NULL value to set context_value". I hope I make the requirement clear to you.
    I am not sure if I am following the right approach to achieve my requirement. if its not right, please suggest me right one.. and if its right please guide me resolve the error..
    Looking forward to your reply.
    Thanks
    Sunil

    Andreas,
    I had already created relations between Matster Block -Tab_A block, Master Block -Tab_B block and Master Block - Tab_C block...
    The point is all the three tabs are created using one table XX_Child only.. I used context_value A,B and C respectively so that once I query the data for XX_Child from backend, I should be in a position to figure out what data is inserted using Tab A, B and C. why I need so .. because If take my entire form in query mode and search for a master record.. then Tab_A, tab_B and Tab_C display their respective data. I hope, I make you understand.. Can you please guide me.
    Thanks
    Sunil

  • 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

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

  • How to build what a parent child record looked like from audit history

    I've got a simple parent child relationship (eg DEPT/EMP) and I have audit triggers on the 2 tables that log any changes. The 2 tables are seen by the User as 1 entity, so if an EMP record changes, that is essentially a DEPT change. I want to show a record where the info shown is correct at that particular point in time.
    Now for a very crude example to illustrate...
    So, says it's 9:00 and we have:
    Dept 1=Sales
    Emp 1=Clark
    Emp 2=Smith
    Now we change Emp 1 at 9:01 to Smythe
    Next we change Dept 2 at 9:02 to Sales UK
    Next we add Emp 3=Jones at 9:04
    Next we change Emp1 at 9:05 to Clarke
    So now if the User looks at the history of Dept 1 they will see it has changed at the following times:
    9:01 (emp change)
    9:02 (dept change)
    9:04 (emp change)
    9:05 (emp change)
    even though the actual Dept table was only changed once.
    This part is easy enough to extract but the next part I'm struggling to get my head around (must be Friday afternoon!).
    The User wants to be able to view what the "Dept" looked like at the time of the change. So we would get the following results:
    9:00 Dept 1=Sales, Emp 1=Clark, Emp 2=Smith (as per original data)
    9:01 Dept 1=Sales, Emp 1=Clark, Emp 2=Smythe
    9:02 Dept 1=Sales UK, Emp 1=Clark, Emp 2=Smythe
    9:04 Dept 1=Sales UK, Emp 1=Clark, Emp 2=Smythe, Emp 3=Jones
    9:05 Dept 1=Sales UK, Emp 1=Clarke, Emp 2=Smythe, Emp 3=Jones
    I'm trying to write a bit of SQL to do this but the tricky bit comes in due to having 2 different tables that have triggered the change to a "DEPT". I see the output as being as many rows as there are children, so the raw output for the above summary would be along the lines of:
    9:00, Dept 1=Sales, Emp 1=Clark
    9:00, Dept 1=Sales, Emp 2=Smith
    9:01, Dept 1=Sales, Emp 1=Clark
    9:01, Dept 1=Sales, Emp 2=Smythe
    9:02, Dept 1=Sales UK, Emp 1=Clark
    9:02, Dept 1=Sales UK, Emp 2=Smythe
    9:04, Dept 1=Sales UK, Emp 1=Clark
    9:04, Dept 1=Sales UK, Emp 2=Smythe
    9:04, Dept 1=Sales UK, Emp 3=Jones
    9:05, Dept 1=Sales UK, Emp 1=Clarke
    9:05, Dept 1=Sales UK, Emp 2=Smythe
    9:05, Dept 1=Sales UK, Emp 3=Jones
    Any help appreciated!!
    An alternative to all this is to make my trigger on each table populate this info (ie write whatever is currently in place) into a table structured as I have mentioned above (so Dept i denormalised) but that looks to be a bit messy.

    Two tables, Dept and Emp. Both have audit triggers inserting into it's own audit table.
    create or replace table DEPT(
    dept_no number,
    dept_name varchar2(50),
    dept_city varchar2(50));
    create or replace table EMP(
    emp_no number,
    emp_surname varchar2(100),
    emp_firstname varchar2(50),
    emp_dept_no number);dept_no pk of DEPT
    emp_no pk of EMP
    emp_dept_no FK from EMP to DEPT.dept_no
    create or replace table DEPT_AUDIT(
    dept_no number,
    dept_name varchar2(50),
    dept_city varchar2(50),
    audit_date_time date);
    create or replace table EMP_AUDIT(
    emp_no number,
    emp_surname varchar2(100),
    emp_firstname varchar2(50),
    emp_dept_no number,
    audit_date_time date)
    create or replace trigger dept_audit
    after insert or update
    on dept for each row
    begin
      insert into dept_audit(dept_no, dept_name, dept_city, audit_date_time)
      values(:NEW.dept_no, :NEW.dept_name, :NEW.dept_city, sysdate);
    end;
    create or replace trigger emp_audit
    after insert or update
    on emp for each row
    begin
      insert into emp_audit(emp_no, emp_surname, emp_firstname, emp_dept_no, audit_date_time)
      values(:NEW.emp_no, :NEW.emp_surname, :NEW.emp_firstname, :NEW.emp_dept_no, sysdate);
    end;My above example (ignoring that the columns don't match up but hopefully you get the drift) would end up with the following results in the 2 audit tables:
    DEPT_AUDIT
    9:00 Dept 1=Sales (insert)
    9:02 Dept 1=Sales UK (update)
    EMP_AUDIT
    9:00 Emp 1=Clark (insert)
    9:00 Emp 2=Smith (insert)
    9:01 Emp 2=Smythe (update)
    9:04 Emp 3=Jones (insert)
    9:05 Emp 1=Clarke (update)
    As I said originally, I want to get a view of what the "DEPT" looked like at a particular time and to do this I need to take into account the EMP changes for the DEPT which is why my results would be as follows:
    9:00 Dept 1=Sales, Emp 1=Clark, Emp 2=Smith
    9:01 Dept 1=Sales, Emp 1=Clark, Emp 2=Smythe
    9:02 Dept 1=Sales UK, Emp 1=Clark, Emp 2=Smythe
    9:04 Dept 1=Sales UK, Emp 1=Clark, Emp 2=Smythe, Emp 3=Jones
    9:05 Dept 1=Sales UK, Emp 1=Clarke, Emp 2=Smythe, Emp 3=Jones
    Though what I really want is the rows that make it up like:
    9:00, Dept 1=Sales, Emp 1=Clark
    9:00, Dept 1=Sales, Emp 2=Smith
    9:01, Dept 1=Sales, Emp 1=Clark
    9:01, Dept 1=Sales, Emp 2=Smythe
    9:02, Dept 1=Sales UK, Emp 1=Clark
    9:02, Dept 1=Sales UK, Emp 2=Smythe
    9:04, Dept 1=Sales UK, Emp 1=Clark
    9:04, Dept 1=Sales UK, Emp 2=Smythe
    9:04, Dept 1=Sales UK, Emp 3=Jones
    9:05, Dept 1=Sales UK, Emp 1=Clarke
    9:05, Dept 1=Sales UK, Emp 2=Smythe
    9:05, Dept 1=Sales UK, Emp 3=Jones
    Hope that is a bit clearer.
    thanks for taking time to look.

  • QA_RESULTS_INTERFACE, entring parent-child records.

    I am unable to create parent - child relationships while using QA_RESULTS_INTERFACE and import program.

    I am unable to create parent - child relationships while using QA_RESULTS_INTERFACE and import program.

  • Populate Parent/Child records with "Family" value

    Hi,
    I typically do the task I'm asking assistance with in Excel and it works great... the only problem is that it's VERY slow and takes a lot of work when over 1 million rows as you must split it up and yeah just painful! But what I'm trying to accomplish is
    pretty straight forward for Excel, however escapes me in T-SQL! I have an ordered number that is sorted asc. I have a flag that indicates a record is the "Parent". I want to update the family value for the "Parent" and all sequential records
    until the next "Parent" records is reached. So here is an example in Excel.
    Using the following formula in cell C2 and pasting all the way to the last record, I can easily(for smaller sets anyway) create my desired results.
    =IF(B2="Y",A2,C1)
    Number Flag Family
    1 Y 1
    2 1
    3 1
    4 1
    5 1
    6 1
    7 1
    8 1
    9 Y 9
    10 9
    11 Y 11
    12 11
    13 11
    14 Y 14
    15 14
    16 14
    17 14
    18 14
    19 14

    I have an article on this exact topic
    Fixing
    Missing Data Based on Prior Row Information
    It shows the concept of using OUTER APPLY to achieve desired functionality.
    For every expert, there is an equal and opposite expert. - Becker's Law
    My blog
    My TechNet articles
    I wish I knew how to apply this OUTER APPLY solution to an update statement so I could use. Would this be more efficient and faster than the solution provided by RyanAB? I have millions of records and NOT enough time... the fastest solution is definitely desired!!!
    I ended up using this as a solution as it was the fastest. I first did:
    SELECT a.Number, M.Number 'Family' into FamilyTable FROM Table a
    OUTER APPLY (
    SELECT TOP (1) *
    FROM Table b
    WHERE a.Number >= b.Number and b.[Flag] = 'Y'
    ORDER BY b.[Number] DESC) M
    ORDER BY 1, 2
    Then updated the original like so:
    update a set a.Family = b.Family
    FROM Table a inner join FamilyTable b
    on a.Number = b.Number
    Thanks to all!!!

  • Merging of Parent-Child record

    Hi SDNers,
    I have a query about mearging record in Import Manager.
    I need your advice in Mearging a record which is not at leaf level but at Node level.
    To make it clear:
    For Ex:
    Country
    > State
    >> City 1
    >>> Region
    >>>> District
    >> City 2
    >>> Region
    >>>> District
    I need to merge City 1 and City 2 (tht's at Node level)
    PS: As for thins example I am  able to merge @ District level what i need is mearging at City level
    Regards,
    Krutarth

    Hi Maheshwari,
    Thnx for prompt responce.
    Could you extend the methodology with some details.
    Regards,
    Krutarth

  • Insert Record with Parent/Child Tables doesn't work with Oracle - unlike AC

    Hi,
    I just Migrated a MS Access 2010 Database to an Oracle 11g Backend with the SQL Developer Tool.
    The Migration went fine, all the Tables and Views are migrated.
    I'm working with MS Access as Frontend.
    The application has some Datasheets with Subdatasheets with Parent/Child Relationship. (1-n Relationship)
    After changing to Oracle, it's not possible, to Insert a new Record in a Subdatasheet I always get the following Error Message:
    "The Microsoft Access database engine cannot find a record in the table 'xxxx' with key matching field(s) 'zzzzz'"
    It used to work perfect with the MS Access Backend, do I need a trigger which first adds the child Record ?
    Or what should I do?
    Thank you

    Hi Klaus,
    Thanks for your answer. I still haven't solved my problem. The only way would be to use a singel 1:n Relationship, but in fact I need a n:m Relationship.
    I tried the same scenario with a new Access Application, same result.
    To clearify my problem.
    Goal: Parent Form with Parent Records, Linked Child Form with Child Records in a Datasheet View => Insert of a NEW Child Record.
    I have 3 Tables (table1 = Parent tabel, table2 = Child Table, table12 = n:m Tabel with PK and two FK)
    The Recordsource of the Parent Form is Tabel1
    The Recordsource of the Child Form is Table2 joined with Table12.
    In my Old Access Project, Access Triggered the Insert and filled Table12 with the NEW PK of Table2.
    It seems like Access can't do that anymore....
    I'm pretty desperate and I'm sure it is just a litte thing to fix.....

  • Parent-Child in XML Publisher

    Hi,
    I am working on a report which requires a parent child relationship.
    There are two tables STG1 and STG2
    STG1 STG2
    30012 1
    2
    30040 1
    For each value in STG1 there might be more than one value in STG2.
    After printing the 1st valuesin STG1(30012), the report should print 1 & 2 in STG2(for 30012) and then should go to STG1 (30040) and then print the value 1(for 30040) under it.
    Instead after printing 1st values in STG1(30012). the report is printing all the values in STG2 and then going to 30040 and it is not pringint the 1 for 30040.
    Could some one help , how to resolve the issue.
    Thanks and Regards,
    BALU

    Can you show the XML from the data source?
    I am missing something in what you wrote:
    There are two tables STG1 and STG2
    STG1 STG2
    30012 1
    2
    30040 1

  • 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

Maybe you are looking for

  • While creating RFx getting error

    hi we are using SRM 7 SP13 classic scenario.while creating RFx getting error. Line 0001: Item type 'Service' not allowed for this Item. i created SC with free text and selected type -service .when purchaser is trying to create RFx getting error like

  • Numbers being replaced with periods in PDF

    I'm working on tagging PDFs to be 508. All of the pdfs have already been made and the tagging is being done in Acrobat Pro 8. The problem is seen in the "content" window looking at the tags. The document text can be seen and numbers like "1s", "2s",

  • How to read Standard JSR Portlet Web.xml's context-param

    Hi I am completely new to Java. I want to keep some configuration in Web.xml in Context param. My Web.xml looks like <context-param> <param-name>ConfigUrl</param-name> <param-value>http://localhost:8083/</param-value> </context-param> How can I read

  • Help. songs were added but dont show up on ipod

    I have added the songs to my ipod using itunes, and they show up in i-tunes, and when i look at the disk drive. But they do not show up on my ipod. They are taking up space on the ipod hard drive but they arent appearing. It says 0 songs when i look

  • Reporting Issue

    Dear All, How we can Restrict the values in Parameters/ Select-Options. Rewards Regards Vikas