Trigger that sums free days

Hi to all,
I try to write a trigger that fires after an insert or update that drives me crazy!
My problem is the following: I have a table HOLIDAYS where I have all my free days in a year, always the name and than the number of days, e.g. ('smith', 5). Totally I have 30 days free a year which I can plan. But when I take at least 20 days free from january to march and / or from october to december I get one more day free, so I have 31 days then. I tried to write the trigger that it sums all the free days with the updated or inserted name with the time conditions in the where clause. But nothing works.
Can anybody help me please?
Thanks Mandy

But I get always ora errors:Firstly, a rant. You don't give us the error numbers, I guess that might make things too easy for us. Look, if I'd wanted to spend my time pulling teeth I'd have gone into dentistry. Help us to help you.
Now I've got that off my chest I'm prepared to take a wild guess. It's ORA-4088, the mutating table bomb. The problem is you are querying the table you are inserting, which causes problems for transactional integrity. When Oracle sums the rows should it include the row that's currently being inserted? What if the next row inserted is also for 'SMITH' - should Oracle go back and recalculate the previous row? These are not simple questions to answer. Processing the SUM() statement leaves the database in an unpredictable statement and that's not allowed. So Oracle hurls ORA-4088 instead.
There are solutions to this problem around. They tend to involve flag setting, packages, even jobs - all gnarly stuff. The reason it's so difficult is because the information you are trying to capture is not normal (i.e. not 3NF). It is entirely derivable:
no_of_days free = allowance - sum(END-BEGIN).
Ah, you say, but what about weekends, etc. Well, the inimitable Connor MacDonald has a solution for calculating Business Days on his website (find it here). I also suggest you take his advice about a table for holding public holidays.
Now you know how to calculate the amount of holiday taken, you can include the calculation as a function in a view over the HOLIDAYS table. This (in my opinion) is a more elegant solution than pfaffing around with flags, triggers and packages.
Cheers, APC

Similar Messages

  • I bought a MacBook Pro 13" last week with Snow Leopard pre-installed. Now I am looking to upgrade to Lion. Is there a 30 day window to do that for free? I cannot review my App Store id since I do not have a Credit Card. What to do?

    I bought a MacBook Pro 13" last week with Snow Leopard pre-installed. Now I am looking to upgrade to Lion. Is there a 30 day window to do that for free? I cannot review my App Store id since I do not have a Credit Card. What to do in this case to install Lion. Please help. 

    Hi,
    Use this Info to Contact Apple Support in your Country
    http://www.apple.com/in/support/
    (91) 1800 4250 744 or (91) 80-4140-9000

  • I added an app that said FREE then it is giving to me for 14 days,,,I want to delete it and do not know how..

    I added an app that said FREE then after installing it said I had a 14 day trial..I want to delete this and do not know how

    If you downloaded the app in iTunes on your computer, and synced the iPod touch, you can unselect the app in iTunes, in the iPod's sync settings for Apps, and Sync the iPod again.
    If you downloaded the app directly on the iPod touch, tap and hold on the app's icon (on the iPod's screen).  The icons start to "jiggle."  Click the X next to the app's icon, to remove that app from the iPod.

  • Iphone 5 is stuck on "Update Requested" while trying to download ios8 and it's been like that for 2 days now. I have plenty of space almost 8gb free. Any ideas?

    Iphone 5 is stuck on "Update Requested" while trying to download ios8 and it's been like that for 2 days now. I have plenty of space almost 8gb free. Any ideas?

    Hi Risdian, thanks for the comments and suggestions, however none seemed to lead to any success. When setting the carrier off automatic, after a few seconds of searching the device returns the message, "Unable to load network list", and I have placed my sim into another unlocked iPhone 5 and it worked perfectly, picking up service almost immediately. I can also iMessage and connect to wifi fine, so i don't fully understand the issue.
    I guess my iPhone is in need of repair, so if there are no other conceivable 'at home' fixes, i'll have to bring the phone to the apple store for a diagnosis. Any other suggestions or comments would be happily welcomed
    Thanks for replying and commenting, you were very helpful

  • Which HR KF ? Cumulative/NonCumulative (Aggregation Type= "SUM", "Last Day)

    Hello all,
    For planning at Headcount Level, I was wondering which KF should be used ?
    1) Headcount FTE 0HDCNT_FTE (Cumulative)
    2) Headcount FTE 0HDFTE_NC  (NonCumulative)
    Note that 0HDCNT_FTE is of Aggregation Type = "SUM", "Last Day".
    I was wondering if anyone has used the cumulative (0HDCNT_FTE) in a Transactional Cube ? Are there any problems with these ?
    Any feedback would be most appreciated!

    Hi,
    If you are using the head count KF (0HDCNT_FTE) as cumulative then the Number of employess(Head Count) wont be matching at any time.
    Eg: Let today the KY value is 1 employees
    Tommrow if one more guy joine the new Count will be 2
    Now if you go for cumulative sum, it will be 1+2 = 3
    Hope you got it.
    Regards
    Happy Tony

  • I got charged five times for apps that were free

    I got charge five time for apps that were free. I am frustrated because they have it setup where you can not talk to anyone. Everything is either email or a schedule date far out.

    Was this when downloading them, and if so did you change (5 times) your credit card details on your iTunes account ? Each time that you do so a small temporary store holding charge may be applied to check that the card details are correct and valid and that it's registered to exactly the same name and address as on your iTunes account - your card issuer should remove it within a few days or so.
    Store holding charge : iTunes Store & Mac App Store: About payment card authorization holds

  • HT3702 I only download things that are free from App Store, but sometimes it doesn't let me download something saying there is a problem with a previous purchase?  So why won't it let me??

    Why won't the App Store let me download things that are free, just because I don't have money on my card sometimes, it's free so I just don't get it??

    You can try to make a new account on iTunes Store if you didnt have yet.
    I had the same problem with iTunes Store, the only thing you can do is to put some money on that credit card you are using with you account. iTunes Store already keeping some money for the last purchase you made you can see all info on the Account option and then Purchase history ...

  • HT204266 I am trying to connect a blackberry playbook to the Mac.  I have OS 10.5.1 and it says I need OS 10.6.  Is that a free update or do I have to purchase a new OS?  I just want to load music on to the playbook.

    Trying to connect a blackberry playbook to the Mac.  It says I need OS6.  Is that a free update or do I have to buy a whole new operating system?  Just want to download some music to the playbook.  Also, is it possible to use a iTunes card directly to the playbook and bypass the Mac?  Thanks for any info you can provide.

    The Snow Leopard 10.6 DVD should still be available from Apple for $20. You will have to call Apple Customer Care 1-800-692-7753 or 1-800-676-2775 to purchase it. It may still be in the Legacy Products list. The App Store which is required to download 10.7 or 10.8 is part of the 10.6.6 update.
    If they no longer have any in stock you will have to buy it from eBay or Apple resellers that still have stock. But you will have to pay a premium since the DVDs are no longer being made. Snow Leopard DVDs are already up to $100 on Amazon.
    http://www.ebay.com/sch/i.html?_nkw=10.6+snow+leopard&_sacat=0&_odkw=mac+os+10.6 &_osacat=0

  • Is there a way to default the monthly calendar display so that the current day always shows on top?

    Is there a way to default the monthly calendar display
    so that the current day always shows on top? ie, I want to always be able to see what's in the future 3-4 weeks, not what's in the past 3-4 weeks. The default monthly display is archaic--only allows you to see through the last day of the month. Suddenly today
    is Oct. 30th, and I have a ton of projects lined up in November, but because I haven't been scrolling down every day, I haven't been aware of them every day. I realize there are other tools in Microsoft to help me stay on task, such as reminders and such,
    but it would be helpful if I could always have the current day display on top of the monthly view so I can quickly scan what's coming up in the next few weeks. 

    Thank you!
    Right, I already have it in Month view. My question is a little more specific--I'd like for the current day to always display at the top. For example, today is Oct. 31st, so the current day is at the bottom of the calendar since it is the last day of the month.
    I can view everything in October that I've already completed. What I can't see are the future weeks because we haven't hit November yet. I'd like for the current day to always display at the top of my calendar so I can always see what's coming in the following
    three - four weeks (whether they're a part of that month or not). I've been to other forums trying to find the answer, and have come across the same exact question from frustrated users--but there seemed to be no solution. So I'm posing the question myself
    in this forum. Do you know if this is possible? What I found from other forums is that Outlook defaults to a physical 'desk' type calendar format--so just as I'd use a paper calendar at my desk, I wouldn't be able to see the following weeks unless I either
    flip the page to that month or I come to the first day of the next month, thereby tearing the the old month off and now only able to see the current month. That format is just so...paper...and archaic! Essentially I want the calendars to loop so it doesn't
    even really matter what month it is--I just always want to see what lies ahead without having to scroll down. With our being in the Technology Age, I'd assume this is a logical expectation, but we may be stuck with the replica version of the paper-desk-calendar
    format until Outlook programmers add this Technology Age feature in newer versions.  
    See, this month kind of messed me up because I have so many projects for November that start tomorrow and next week, but I haven't seen them until this week. I would have been better quipped--at least expecting them--had I been able to see all of those projects
    since last week or the week prior.  
    If there is no solution to this answer, would you know how I can contact Outlook to provide feedback? I'm guessing a newer version is on its way...
    Thanks again in advance!

  • Know how memory that is free compared to the maximum allowed

    Hi i want to know how memory is free compared to the maximum memory set in the jre advanced option or the defaut one
    this function is suppose to work, bu im not able to have something good, for example if i set -Xmx256m, so 256mo max thatr the jre can use, and i know that my program use 30mo, i want to see that i have 30mo, but it always give me a weird number, like too low
         * This function will check the maximum memory allowed by the java runtime
         *  and check the number of memory avalaible now and calculate the memory
         *  that is free for using (if he havent enough memory, like only 30M free,
         *  the users will have a message into the java console). The function will
         *  try to release some memory with the garbage collector before displaying
         *  the warning user message
        public void checkMemory()
            /* Call the Garbage Collector and the finalization function 5 times to
                be sure that he has been notified */
            Runtime.getRuntime().runFinalization();
            Runtime.getRuntime().runFinalization();
            Runtime.getRuntime().runFinalization();
            Runtime.getRuntime().runFinalization();
            Runtime.getRuntime().runFinalization();
            System.gc();
            System.gc();
            System.gc();
            System.gc();
            System.gc();
            System.out.println("Total" + Runtime.getRuntime().totalMemory() / 102400);
            System.out.println("Free" + Runtime.getRuntime().freeMemory() / 102400);
            System.out.println("Max" + Runtime.getRuntime().maxMemory() / 102400);
            long freeBytes = Runtime.getRuntime().totalMemory()
                - Runtime.getRuntime().freeMemory();
            long freeMo = freeBytes / 102400;
            if (freeMo < 30)
                System.out.println("You have less than 30mo free for the java "
                    + "runtime, you must close all your internet explorer and open "
                    + "a new session, sorry for the incovenient and thank you");
            else
                System.out.println("ok");   
        //End of checkMemory function
    [\code]
    thx                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    ok i know that isnt ok, if i change my division by /
    (1024*1024) how can i know how to do the things i want
    to do?
    Huh? As I mentioned you are not using a meg. You are using some other number. So something is wrong with that.
    And as I also mention you are using 'total' memory for your calculation instead of 'max' memory - and again I doubt that is what you want.
    >
    by the way mo is mb in french but i used this only for
    myself... didnt think when i wrote the post
    Interesting.

  • What trusted web sites do you use that have free or purchase photoshop brushes?

    What trusted web sites do you use that have free or purchase photoshop brushes?

    The size and resolution depends on the intended output.
    In my opinion relevant zooming shortcuts would be cmd-0 (View > Fit on Screen), cmd-1 (View > 100%) and cmd-spacebar/cmd-alt-spacebar to temporarily switch the current Tool to the Zoom Tool.

  • I have downloaded Mountain Lion and Time Machine says that my Free Agent Goflex (Seagate) external 2gb drive cannot be used as it is read only. I tried disc utility to repair permissions but that block is greyed out. The disc verifies as being OKI

    Since installing Mountain Lion, Time Machine says says that my Free Agent Goflex (Seagate) external 2gb drive cannot be used as it is read only. I tried disc utility to repair permissions but that block is greyed out. The disc verifies as being OKI What next?

    Ok, I solved this problem! I ejected the drive and then disconnected it both from the power supply and the USB connector. I then reconnected everything and powered it up again and Then went into TM preferences and chose the drive as the backup. TM did a new backup (well over an hour) and now works as advertised.

  • Can I cause checking a box to add 1 to a calculated form field?  I have a field that sums the numbers entered in several previous fields and need to be able to add "1" if a checkbox is selected as well.

    Can I cause checking a box to add 1 to a calculated form field?  I have a field that sums the numbers entered in several previous fields and need to be able to add "1" if a checkbox is selected as well.

    I think it has something to do with the way the value of the check box is exported, but I'm not sure.  With nothing being exported to Data5, Data6 displays the sum of Data1-4 rounded down to the nearest whole number and updates automatically as Data1-4 are updated.
    Right now, assuming Data1-4 are 0, where data 5 is the output of the second example and any box is checked,  "1" is displayed in data5 but nothing is added to data 6. Selecting any other check box or deselecting that check box will cause data6 to add 1 even if data5 displays "0".  By way of example:
    Selecting Check box 16 results in Data5 displays 1 and Data6 displays zero.
    Then, if any or all of Checkbox17-20 are selected, Data5 displays 1 and Data6 displays 1.
    Then, if any or all of Checkbox17-20 are deselected, Data5 Displays 1 and Data6 displays1.
    Then, if Checkbox16 is deselected, Data5 displays 0 and Data6 displays 1.

  • The picture that changes ever day when you open up firefox is gone how do I get it back

    How do I reset the home page to show the picture that changes ever day to a different picture when you open up firefox

    What was or is the home page setting that has the images?
    Was that the Google website (www.google.com) with a background image?

  • Trying to download CS6 on my mac pro. when i click on Download, under my orders, it brings up an error page: JRun Servlet error, 413 Header Length to Large. It's been doing this each time I've tried that last few days. What can I do to download this?

    Trying to download CS6 on my mac pro. when i click on Download, under my orders, it brings up an error page: JRun Servlet error, 413 Header Length to Large. It's been doing this each time I've tried that last few days. What can I do to download this?

    clear your adobe.com cookies or use a different browser.

Maybe you are looking for

  • PowerMac G5 will not boot into Open Firmware, or Boot Manager

    I have a PowerMac G5 and it refuses to boot into Open Firmware. I used Command + Option + O + F and held down the Option key. I have tried 3 different Keyboards but no avail.

  • How to Perform Forced Manual Failover of Availability Group (SQL Server) and WSFC (Windows Server Failover Cluster)

    I have a scenario with the three nodes with server 2012 standard, each running an instance of SQL Server 2012 enterprise, participate in a single Windows Server Failover Cluster (WSFC) that spans two data centers. If the nodes in the primary data cen

  • Trigger not firing in linux OS

    Hi All: Initially i am developed a form using form builder and i deployed this form in Windows OS this is working fine when i am deploying this same form in Linux OS that is not working even small trigger also not firing.so here we need to change any

  • [SOLVED]Easy question

    Hello, Could anyone tell me what pacman command writes out the names of  the available upgrades. I would like to know what packages I am upgrading. The pacman -Su doesn't list the names of the packages it is just updating them all. Thank a lot, jmak

  • Images from camera card

    I downloaded images from my camera card into Elements. They have an offline symbol on them and the images are fuzzy. What does this mean and how do I correct it?