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

Similar Messages

  • How to achieve parent-child relationship using self join?

    my table structure is as follows
    parent child name
    -1     1     A1
    1     2     A2
    1     3     A3
    how to achieve the hierarchy model using self join. this can be easily achieved using "connect by prior". but how to achieve the same using self join?

    Hi,
    Yes, that's definitely possible. If you only need to display two levels from the hierarchy, a self-join is a good option. Make it an outer join if you need to show everyone on one level, regardless of whether they have a match on the other level or not; for example, if you want the output:
    child_name     child_id     parent_name     parent_id
    A1          1
    A2          2          A1          1
    A3          3          A1          1It's good that you posted some sample data. Now post the results you want from that data, and your query (what you think is the best attempt you've made so far). If you haven't tried anything so far, then look at some other simple self-join to get ideas.

  • How can provide parent-child nodes relation ships?

    how can provide parent-child nodes relation ships?

    I was under the impression that scenegraph is like a JTree. But in JavaFX only leaf node rendering in scenegraph. This situation was confusing my mind. In JavaFX CustomNode must be extending and return a group for custom leaf. If we want to a create parent-child node hierarchy we are create CustomNode that return a group and this group contain an another group,etc. So there is maybe only a way. If you learning to JavaFX first time.This way don't look familiar.

  • How to create Parent Child relationship of Assets

    Hi All
    can any one provide the solution for the below mention requirment.
    Problem Description: How to create Parent Child relationship of Assets in below case.
    1. If asset Category of Child assets are different but both parent & child assets are already capitalized.
    2. If asset Category of Child assets are same but both parent & child assets are already capitalized.
    3. If asset Category of Child assets are same for new assets.

    Hi All
    can any one provide the solution for the below mention requirment.
    Problem Description: How to create Parent Child relationship of Assets in below case.
    1. If asset Category of Child assets are different but both parent & child assets are already capitalized.
    2. If asset Category of Child assets are same but both parent & child assets are already capitalized.
    3. If asset Category of Child assets are same for new assets.

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

  • How to achieve dynamic page break in Smart form

    Hi
              1.How to achieve dynamic page breaks in Smart forms.
               2.What are the various table types in Smart forms.
    Regards

    <i>Dynamic page break : </i>
    create a node of type COMMAND and in its attributes check "Go to new page".
    <i>There are Tables and Templates in smart forms :</i>
    Use node type <i>Template</i> to display a table whose layout and size (number of lines and columns) is determined before the runtime of the print program else use <i>Table</i>.
    Take a look at <a href="http://help.sap.com/printdocu/core/Print46c/en/data/pdf/BCSRVSCRSF/BCSRVSCRSF.pdf">SAP Smart Forms (BC-SRV-SCR)</a>
    Regards

  • How to set value on MRU insert Tabular Form

    This post refers to the forum article found How to set value on MRU insert Tabular Form
    I have included the problem and proposed solution below. My problem follows
    Problem
    Hi,
    I am using a Tabular Form. I used the wizard and it created all of the items (Cancel, Submit, Add, Multidelete buttons, etc.). I have a table that is like an FK table. For instance, we could have a customer table, and then a customer address table. Each customer could have multiple addresses. In the address table, the first ID column is the customer ID. So in using the tabular form for the addresses, I need to make the first column the same when I insert. But when I choose add row, everything works fine except it tries to insert a null into customer id. The uniqueness of the row is determined by customer ID and address string.
    Any time I make it to this screen, all new rows will have the same ID with I have in a variable that I can reference from the page called :P0_ITM_CUST_ID.
    How do I set the first value for all inserts? My guess is I need to do this in Computations. I'm also guessing I need to do this with a replace statement. I'm just not sure how to reference the first column of the new row.
    Thanks!
    Tim
    Solution
    The way to do this is by using the "Default" value for that Column. Go to
    Home>Application Builder>Application xxx>Page yyy>Report Attributes>Column Attributes
    Set the default value for newly added rows as in
    http://img237.imageshack.us/img237/5758/screenshot012di2.jpg
    Hope this helps.
    Un-resolved problem
    have also tried to do this but the fields I see are not the same.
    Please see screenshot=http://krisjones.freewebspace.com/apex.JPG
    I am using the Oracle hosted environment, so 2.2.1.
    To my knowledge I have done the same as the user in the first post. Am I doing something incorrectly or should I have created the tabular form differently?
    Many thanks. Kris

    Kristian - You see a different version of the form depending on whether the selected column is the primary key column or not.
    Scott

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

  • PL/SQL  on delete cascade..   ( how  to view the child record deleted..?)

    Hai
    i have 70 tables integrated with foreign and child key constraints. i have on delete cascade for all the child tables. if i delete the parent table automatically child table record get deleted.
    Kindly tell me how can i check howmany child record has been deleted ..? how can i monitor this...?
    one thing i can do... i can make count of child table before and after...
    is there anyother way..?
    S

    Peter,
    I subscribe to the general consensus around trigger usage. Allthough I allways diffentiate between triggers that,
    - perform pl/sql with embedded DML (that is: delete, insert, update)
    versus triggers
    - that perform pl/sql with embedded queries only.
    The latter use of triggers is good (in my opinion), and most frequently used to enforce (non declarable) data integrity constraints.
    The former use of triggers is bad. Because it makes things happen automagically.
    Just google "asktom triggers are evil", you'll find statements such as:
    ~quote
    because things happen automagically
    because side effects are bad
    because explicit linear code is more maintainable then "happens as a by product of something in the background"
    magic should be avoided. Experience tells me this.
    ~quote
    And to me a CASCADE DELETE clause on a foreign key definition, is a TRIGGER. Allbeit not one for which you had to write CREATE TRIGGER statements, but one that you can declaratively introduce. And this trigger holds embedded DML, it is of the former case, and is therefor bad.
    You the designer of the application may be aware that you have your FK's as cascade delete. But your successor(s) might not be aware of this when they write maintenance code to delete Orders. They might be expecting the database to throw them an FK violation message when they try to delete an Order that still has Lines attached to it.
    Everybody knows the effect of an INSERT, a DELETE, an UPDATE. But the moment you've introduced triggers with embedded DML in them, the effect of these three well known primitive SQL statements suddenly becomes unknown. With triggers you can create any effect for any of these three primitives, that you want. And more often than not other people maintaining your codebase later on in the future, do not realize these side effects happen, because they didn't check the presence of any triggers, nor investigated the side effects caused by them.
    Btw. for exactly the same reasoning I consider use of DEFAULT-clause on table columns, or even use of (fixed length) CHAR datatype, evil also. Again they are in effect declarative triggers with side effects. Allbeit that their side effects usually are less worse than those caused by handwritten triggers with embedded DML.
    Toon

  • 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 delete the child record from the database

    how to delete a parent and child record from the database can we do it in the servlet and my database is oracle

    I'm not sure I understand the question but you could certainly use the JDBC API from within your servlet to access and modify a DB. You could also use an EJB layer to access your DB and accomplish the same tasks.

  • How to delete parent child relation in Toplink

    Hi All,
    I have 3 tables A,B,C.
    In Table A ,I am saving record.
    Table B & C has parent child relation.
    B-->Parent
    C-->Child
    So I want to save records in Table A.
    And delete from child(C) 1st then from parent(B).
    I m writing my code as,
    em.getTransaction().begin();
    em.persist(Table A);//save in Table A
    em.remove(em.merge(Table B));//Remove from Parent
    But how to delete records from child table then from parent table.
    Thanks
    Sandip

    If you have a @OneToOne relationship between two entities, the join column information is used to order the SQL when you remove two entities. For example, if I have:
    @Entity
    public class Employee implements Serializable {
         @OneToOne
         @JoinColumn(name="ADDR_ID")
         private Address address;
    ...Then the following code runs regardless of the order of the remove calls.
              em.getTransaction().begin();
              Employee parent = new Employee();
              Address child = new Address();
              parent.setAddress(child);
              em.persist(parent);
              em.persist(child);
              em.getTransaction().commit();
              em.getTransaction().begin();
              parent = em.merge(parent);
              child = em.merge(child);
              // order of next two statements unimportant
              em.remove(parent);
              em.remove(child);
              em.getTransaction().commit();If I don't remove the parent and just the child I get the same error you do because of the FK from Employee to Address.
    --Shaun                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • How to filter parent & child rows from tables while export usingData export

    Hi,
    I have a requirement of export schema. Assume there is a account details table and account transactions table under schema.They have parent child relation exist. if i filter accounts from account details the corresponding transactions in account transactions table should be filterd.How to achieve this?
    Regards,
    Venkat Vadlamudi
    Mobile:9850499800

    Not sure if this is a SQL and PL/SQL question or whether it's an Oracle Apps type question or a Database General.
    Whatever, you've posted in the wrong forum (http://forums.oracle.com/forums/ann.jspa?annID=599)
    You should post in a more appropriate forum e.g.
    PL/SQL
    General Database Discussions
    etc.
    locking this thread

  • 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

Maybe you are looking for