I thought this would be simple BUT I guess not!

I have two tables Master/Detail. On the detail table I have a database trigger written for insert, update or delete that updates values not the master. This works perfect. Now I add another database trigger that when the master is deleted the trigger deletes the details (ESTBOMHMST_T1). This would work perfect IF the first trigger (UPDATE_ESTBOMHMST_TOTALS ... after insert,update,delete) was not there BUT that one fires because of the delete ... this causes a mutating table error.
I have tried to understand the section in the database triggers help onsite BUT cannot get the combination of triggers working ...
Simply put I want the database trigger to delete my child details when the master header is deleted AND also (via if the UPDATE_ESTBOMHMST_TOTALS) if the detail is acted upon (updated or perhaps just one detail of many deleted) perform a calculation back to the header to update the totals.
Here is the error I and getting and the two triggers currently being used:
ORA-04091: table SDC.ESTBOMHMST is mutating, trigger/function may not see it ORA-06512: at "SDC.UPDATE_ESTBOMHMST_TOTALS", line 5 ORA-04088: error during execution of trigger 'SDC.UPDATE_ESTBOMHMST_TOTALS' ORA-06512: at "SDC.ESTBOMHMST_T1", line 4 ORA-04088: error during execution of trigger 'SDC.ESTBOMHMST_T1'
create or replace trigger "ESTBOMHMST_T1"
BEFORE
delete on "ESTBOMHMST"
for each row
begin
delete from estbomdmst where ref_no = :old.ref_no;
end;
create or replace TRIGGER "UPDATE_ESTBOMHMST_TOTALS"
AFTER INSERT OR UPDATE OR DELETE on ESTBOMDMST
declare
begin
update ESTBOMHMST set total_mat_cost =
(select sum( nvl(mat_price,nvl(mat_cost,0)) * nvl(qty_required,0) )
from ESTBOMDMST
where ESTBOMHMST.ref_no = ESTBOMDMST.ref_no);
update ESTBOMHMST set total_lab_cost =
(select sum(nvl(lab_cost,0)) from ESTBOMDMST
where ESTBOMHMST.ref_no = ESTBOMDMST.ref_no);
end;
Edited by: user2457943 on Jan 15, 2012 7:28 AM
Edited by: user2457943 on Jan 15, 2012 9:27 AM

Please post the details of your DB version.
Your design is flawed for several reasons.
1. The master table is not normalized. It contains rolled up detail information. A design should almost never do this in an OLTP system. Conversely, in an OLAP system the detail data does not change in real-time so there should be no need to perform real-time rollups.
2. You say 'if the detail is acted upon and detail is deleted ' - but the detail trigger code makes NO distinction between INSERT, UPDATE or DELETE operations. Worse the DML for a single detail record attempts to cause the trigger to recalculate the master data for ALL RECORDS and not just the record based on the key value for the detail record that changed. Why are you trying to recalculate summary data for detail records whose data has not changed? That is a design flaw and will never perform anyway.
3. For OLTP systems the rollups of detail data can easily be performed using standard Oracle queries, analytical functions or customized views.
4. For OLAP systems the rollups are typically done as a batch operation after or during the process of updating the master/detail records.
5. Oracle already has functionaliity to delete child records when a parent record is deleted. You create a foreign key constraint on the child that uses the clause ON DELETE CASCADE. When a parent record is deleted the child records will also be deleted. Since there will be no more parent record there will be no child records to roll up. So the entire DELETE portion of both triggers is unnecessary in any case.

Similar Messages

  • Extend existing tsql query to get all customers, even if they have no instances of the previous query - thought this would be easy, but...

    Hi all,
    The previous query is absolutely ok.
    The only thing i want to change is ...
    get all the previous available ve1 AND NEW: if a AGNR has no ve1-instance, regardless get an ve1-instance with the agnr filled but f.e. the other fields empty
    The grouping could made in reporting-logic later, and not in the tsql-query.
    resultset i need:
    - all agnr, if the have an ve1-instance or not
    Groups (hierarchy) i need, later in Report:
    - AGNR
       - ve1 (with all the left joind fields pg, vnfk, vnpk, vm (if they are)
       - if a agnr has no instance of ve1 --> print: "NO ver available"
    SELECT
    ve1.new_verid,
    ve1.new_no,
    ve1.statuscode,
    ve1.statuscodename,
    ve1.createdon,
    ve1.createdby,
    ve1.createdbyname,
    ve1.new_begin,
    DATEPART(yyyy, ve1.new_begin) AS begin_year,
    ve1.new_end,
    ve1.new_vn_fid,
    ve1.new_vn_fidname,
    ve1.new_vn_kid,
    ve1.new_vn_kidname,
    vnpk.new_how_old,
    ve1.new_vg,
    ve1.new_vgname,
    ve1.new_vs,
    ve1.new_vsname,
    ve1.new_vstat,
    ve1.new_vstatname,
    ve1.new_zw,
    ve1.new_zwname,
    ve1.new_bn_zw,
    ve1.new_rlz_v,
    ve1.new_pgid,
    ve1.new_pgidname,
    pg.accountnumber as pg_accountno,
    ve1.new_agnr_agnr_avmid,
    ve1.new_agnr_agnr_avmidname,
    AGNR.new_vm_kid AS vm_contactid,
    AGNR.new_vm_kidname AS vm_contactidname,
    ve1.new_efv,
    ve1.new_efvname,
    CASE
    WHEN ve1.new_vn_kid IS NOT NULL THEN 'Private Customer'
    WHEN ve1.new_vn_fid IS NOT NULL THEN 'Account Customer'
    ELSE 'Kunde'
    END AS kunde_typ,
    DATEPART(yyyy, vnpk.birthdate) as vnpk_birth_year,
    CASE
    WHEN ((ve1.new_rlz_v IS NOT NULL) OR (ve1.new_rlz_v > 0))
    THEN ve1.new_rlz_v
    WHEN (DATEPART(yyyy, ve1.new_begin) IS NOT NULL) AND (DATEPART(yyyy, vnpk.birthdate) IS NOT NULL)
    THEN 65 - ((DATEPART(yyyy, ve1.new_begin)) - (DATEPART(yyyy, vnpk.birthdate)))
    ELSE 20
    END AS vlz_calc,
    CASE
    WHEN ((ve1.new_bnj IS NOT NULL) OR (ve1.new_bnj > 0)) THEN ve1.new_bnj
    WHEN ((ve1.new_bn_zw IS NOT NULL) OR (ve1.new_bn_zw > 0))
    THEN
    CASE
    WHEN new_zw = '100000008' THEN ve1.new_bn_zw * 12
    WHEN new_zw = '100000004' THEN ve1.new_bn_zw * 4
    WHEN new_zw = '100000002' THEN ve1.new_bn_zw * 2
    WHEN new_zw = '100000001' THEN ve1.new_bn_zw * 1
    WHEN new_zw = '100000006' THEN ve1.new_bn_zw
    ELSE 0
    END
    ELSE 0
    END AS bnj_calc
    FROM
    Filterednew_ver AS ve1
    LEFT OUTER JOIN Filterednew_agnr AS AGNR
    ON ve1.new_agnr_agnr_avmid = AGNR.new_agnrid
    LEFT OUTER JOIN FilteredAccount AS pg
    ON ve1.new_pgid = pg.accountid
    LEFT OUTER JOIN FilteredAccount AS vnfk
    ON ve1.new_vn_fid = vnfk.accountid
    LEFT OUTER JOIN FilteredContact AS vnpk
    ON ve1.new_vn_kid = vnpk.contactid
    LEFT OUTER JOIN FilteredContact AS vm
    ON AGNR.new_vm_kid = vm.contactid
    WHERE
    (ve1.createdon >= @Begin_Week)
    AND (ve1.createdon <= @End_Week)
    AND (ve1.new_vg = @vg)
    AND (ve1.statuscode = '1')
    AND (ve1.new_efv <> '100000000' OR ve1.new_efv IS NULL)
    AND (ve1.new_vstat <> '100000004' OR ve1.new_vstat IS NULL)
    AND (ve1.new_zw IN ('100000008','100000004','100000002','100000001','100000006'))
    ORDER BY
    ve1.createdon
    i thought, and tried with right joins, but i think i need to change the sight (the complete query)?
    thx for all kind of help
    Greets Peb

    Hi Peb,
    Please provide sample data and expected results.

  • I need to recover deleted data from my iPhone 4S but don't have a recent backup. I thought by pressing sync on my macbook this would back up-but I was wrong. There are no backups on my macbook and the latest backup on iCloud was Jan 2012. Please help

    I need to recover deleted data from my iPhone 4S but don't have a recent backup. I thought by pressing sync on my macbook this would back up…but I was wrong. There are no backups on my macbook and the latest backup on iCloud was Jan 2012. My mum died in May and I had lots of text messages that I wanted to keep. I really want to get them back. Is there any way at all I can get that deleted data from the phone?

    Since it has always been very basic to backup your computer and all it's data, Apple provides no way for you to transfer music from your iPhone back to your computer.  As you know, you can re-download all iTunes purchases, but music that you ripped yourself you'll have to just re-rip again.
    You can try and find 3rd party applications that might help you.  I'm sure you'll pay, however.
    Let this be a very important lesson learned.
    Best.

  • How do i change the email address for my icloud account on my 4s. when i sign in on line it is my new email address so i thought it would change automatically but obviously not!

    how do i change the email address for my icloud account on my 4s. when i sign in on line it is my new email address so i thought it would change automatically but obviously not!

    Settings>iCloud...scroll down...delete account. Then setup iCloud with your new ID.
    You can't change the Apple ID for your iCloud account, you have to delete it.

  • I thought I had  Adobe stuff.  I am not computer saavy at all, so I need to speak to someone who can guide me through this situation.  I thought I had an Adobe PDF File, but I guess not.  When I went to print taxes, the blank forms printed, but no the tax

    I thought I had Adobe stuff.  I am not computer savvy at all, so I need to speak to someone who can guide me through this situation.  I thought I had an Adobe PDF File, but I guess not.  When I went to print taxes, the blank forms printed, but no tax information I typed in. Please have someone call me.  My number is (909) 864-1150.  Thank you.

    Hello Bill,
    You can seek help from Adobe customer care for the same.
    Contact Customer Care
    Regards,
    Anubha

  • I recently bought an iPhone 5s from boost mobile I thought service would be decent but it really *****. I'm wondering if there is any way I can switch carriers maybe to us cellular seeing that they recently added new prepaid plans

    I recently bought an iPhone 5s from boost mobile I thought service would be decent but it really *****. I'm wondering if there is any way I can switch carriers maybe to us cellular seeing that they recently added new prepaid plans and have good service in my area.  I do know boost operates with sprint but  not sure what I can do because having an expensive phone with crappy service really *****

    Sorry, but Boost reportedly does not offer unlocking for iPhones, so you're stuck with them unless you can return the iPhone for a refund and cancel the service, or can sell the iPhone to someone who could use it with Boost.
    Regards.

  • Hello, I bought 3 lihtroom I would be upgreed, I have this to prove it but I do not have my serial n

    Hello, I bought 3 lihtroom I would be upgreed, I have this to prove it but I do not have my serial number what to do?

    But yes I know, but I despair the phone does not respond, the chat is closed and no mail? what to do
    Le 27 mars 2014 à 16:09, JimHess <[email protected]> a écrit :
    Re: Hello, I bought 3 lihtroom I would be upgreed, I have this to prove it but I do not have my serial n
    created by JimHess in Photoshop Lightroom - View the full discussion

  • Just installed a new time capsule and i want to use my airport express to extend my wireless range....time capsule working with existing devices at this time...but i am not able to get airport utility to recognize the airport express.....????

    just installed a new time capsule and i want to use my airport express to extend my wireless range....time capsule working with existing devices at this time...but i am not able to get airport utility to recognize the airport express.....????

    Temporarily connecting your AirPort Express to one of the Time Capsule's Etherent LAN <-> ports...as LaPastenagure suggests....is always a good way to setup and configure other network devices.
    If you want to configure the Express using wireless, remember that the Express broadcasts a default wireless signal with a name like Apple Network xxxxxx. You must log on to this network first....no password is required....then open AirPort Utility to "see" the AirPort Express.

  • How do I get music already on my laptop on (amazon, Emodio, Windows media player) into my itunes library, I have just done the icloud match as I thought this would do it for me, but the only songs on my phone are the 40 that I already had in itunes..

    How do I get music already on my laptop into my itunes account library? I have just done the icloud match thinking this would pick them all up, but it hasn't, all it has done is match the 40 songs I already have in my itunes library. I wanted to get some more  music onto my iphone and I am stuck. If someone could assist, that would be great. Thanks. Sue

    Suzybabe wrote:
    Fantastic, how easy this was, searched and searched through itunes help and forums earlier today and this little gem of instruction is nowhere to be found.
    Many thanks ed2345.
    Sue
    Sue,
    Glad to hear that it was helpful.  Enjoy the music!
    Ed

  • TRYING TO SET UP I PAD TO HP AIR PRINTER HAD PROBLEMS WITH ,TALKTALK ROUTER, ASKED AT PC WORLD ADVISED TO BY AIRPORT EXPRESS BUT STILL NO LUCK WILL NOT COMPLETE SET UP. THOUGHT THIS WOULD REPLACE THE ROUTER, I THINK I MAY HAVE BEEN WRONGLY ADVISED

    Having problems with air printer to i pad, problem seems to lie with talktalk router, hp solutions managed to get i mac to air printer working but not i pad, adivsed to buy another router as talktalk is not compatiable with bonjour. Went to PC world apple department advised to by airport express. tried setting it up using but will not finalise. i was led to believe this would replace the talktalk router? i feel i have been sold the wrong thing. Any suggestions

    This happened to me when I was setting up the wireless router for a friend.  The issue is with the Westall modem.  You need to go in and setup the "bridge" option on the westell modem.  The link below gives directions or you can call bellsouth dsl support (this is how I learned about it).
    http://help.bellsouth.net/bellsouth/asp/contentview.asp?isbrowse=true&sprt_cid=3f993409%2Ddff7%2D422...
    Good luck
    Solution:
    Method 1 - Hard Reset
    Restore the modem to default settings by pressing the Reset button on the back of the modem and holding it for 3 seconds. (Bridged mode is the default setting for the Westell).
    After the modem regains sync, it is in Bridged mode. Do not attempt to surf into the modem as surfing into the modem will enable the Easy Login page and convert the modem from bridged mode to a PPP mode.
    Method 2 – Bridged Mode
    Access the Westell interface using http://192.168.1.254 or http://launchmodem.
    Click on the Broadband DSL Line button. 
    Click on the Protocols button 
    Select the radio button to the left of Option 2 (Bridge)
    Click the save button. Once the modem has restarted it is in bridge mode. 
    ALL STEPS COMPLETE

  • How to create NEW Pdf from SELECTED pages?! thought this would be so easy!

    I am finding it hard to believe how much time I've sunk into trying to figure this out. I thought it would be as simple as me selecting different pages, right clicking, and then finding "new document from selection," or something like that.
    I have a PDF with about 300 pages. I have a list of page numbers that I need in a NEW PDF. What is the easiest way to do this? Thanks so much.
    -Eric

    I created a tool that does just that (only you will need to enter the page numbers as text, it does not work by selecting them):
    Acrobat -- Extract Non-Sequential Pages: http://try67.blogspot.com/2011/04/acrobat-extract-non-sequential-pages.html

  • I know this should be easy, BUT IT'S NOT!!  help!

    Hey everyone,
    I decided to swallow some pride and find some solution to my situation that should be simple. I've looked on many of the threads and still can't seem to find the solution.
    I am just trying to set up my Airport Express to my Powermac G5. Very simple... just want to run the ethernet through the Express from another room.
    I started by plugging in my Express. That was fine, I got a green light. Then when to Setup Assistant... it cannot find a network. After many attempts, still no network. I tried to reset my Express. No luck. I also configured my Express directly to my Powermac, all settings seemed just fine... except when I try to use it how it is supposed to be used, I get nothing. My G5 is reading my Extreme Card okay. So... what in the world am I doing wrong?
    Admittedly, I am no tech whiz when it comes to networking, so naturally, I assumed that this would be a simple and quick installation... that has seemed to last for hours and hours...
    Powermac Dual 2Gh G5, 4G RAM   Mac OS X (10.3.9)  

    Hi
    I had the same or similar problem when I first hooked up my airport. I took my computer to the Apple store to be sure my airport setup was correct. When they turned on my computer it immediately connected to their network. They had no idea why it wouldn't work at home. I was lucky that a person was standing there that had an idea what was wrong. He said it was possible that there was some interference in my home. So, the apple people suggested that I change from automatic to a specific channel. That was fine, except I asked them how could I do that if the computer didn't recognize the base station? So, we then tried hooking the base station up directly to the computer using an ethernet cable, and it worked (they had never tried this). When I got home I did this and changed the channel to 2 (you have about 10 or so channels you can try). I then put the base station back to the room where my cable is. The computer immediately recognized it. I now have three airport extremes in various rooms and they all work great, as long as I set them to a specific channel. You can try each channel and then check the strength of the signal to determine which is the best for your environment.
    Hope this helps.
    Larry

  • Is there a separate download for iMac.  I bought and downloaded what I thought was the right download but it is not working and feel it might be a windows version.  How doe I get it right

    s there a separate download for iMac.  I bought and downloaded what I thought was the right download but not working and feel it might be a windows version.  How doe I get it right

    Check the link below for requirements and instructions for upgrading to Snow Leopard (10.6)
    http://store.apple.com/us/product/MC573/mac-os-x-106-snow-leopard

  • I have no photo edit in iPhoto it should be simple but its just not there can you help

    Hi
    i have no photo edit in iPhoto it should be simple as click and it comes up but it is not there
    hope someone can help
    thanks

    Nope - you actually have to share details as  can not see your computer
    See hints here - Writing an effective Apple Support Communities question - and - Find answers and ask new questions
    LN

  • HT4191 I have lost several days notes with the note app. What could be the issue? I have attempted to sync with my email account but noticing appears in my email. I thought this would act as a backup. Also how do I verify where the notes were being saved

    I keep losing notes once I've added them. I don't know how to confirm where they are being stored. I'm wondering if the storage could be full. Also tried to sync with my yahoo account thinking that might help. But not sure how I get existing notes to sync with the account....they didn't  show up once I turned that feature on.

    were using icloud?
    you can check to see if there by logging into your account at icloud.com

Maybe you are looking for

  • Report in HTML web service... unnecessarity tags added

    My requirement is to generate a report in html format in sap and get it through a  web service. I need to invoke a sap web service which executes a report function and returns the report in HTML format. I am using an RFC BAPI which uses WWW_HTML_FROM

  • Null pointer exception with an array?

    import java.awt.*; import javax.swing.*; /* Author: Mike Megally    Problem: Chapter 2, Question 18*/ class Yearly{   private double deferred;   private double taxed;   private int year;   public void setdeferred(double amount){     deferred = amount

  • Content Database large after removing BLOB

    My content database was 3 gigs before removing BLOB. In the process of removing BLOB, it required a merge which moved all of the files from the BLOB to my content database and made it 32 gigs. I then deleted the site containing all of the documents,

  • Can't open attachments of archived e-mails

    We have recently started using Mail at our design agency. Upon completion of jobs we have backed-up, restored and archived all mail into their relevant job folders. We have then found, when needing to go back to old e-mails, the attachments cannot be

  • How to open an URL with PLSQL FUNCTION?

    Hi friends, I want to know if EBS has a package to open an URL like this xxpck.openhtml("http://www.oracle.com")