Help to avoid mutating problem of my trigger

Hi, Guys:
I have a question maybe silly. I need to maintain a table named as "SOR_Email_Config" with a trigger. Whenever there is an event to update a column named as "Current_Setting" from 'N' to 'Y' with a row, this trigger needs to check other rows in the same table to make sure other rows' Current_Setting is 'N', if other rows has 'Y' on "current_setting" column, the trigger needs to update it to 'N'. the code is as follows:
CREATE OR REPLACE TRIGGER SOR_NOTI_CONFIG_UPDATE_TRG
BEFORE INSERT OR UPDATE OF CURRENT_SETTING ON SOR_EMAIL_CONFIG
FOR EACH ROW
WHEN (new.current_setting='Y')
BEGIN
  update SOR_EMAIL_CONFIG
  set current_setting='N';
END;Obviously, I got a mutating problem, so how can I implement this trigger to avoid mutating problem?
Thanks in advance
Sam

Hello Sam,
you are posting in the wrong forum, because this one is for the SQL Develper tool and not for general SQL questions.
Having said that, you could try autonomous transactions but this could lead to deadlocks and other bad things.
Hope that helps,
dhalek

Similar Messages

  • Before Update Trigger has mutating problem

    I'm getting a mutating problem with this updating trigger. I'm not sure how to deal with it. Here is my code:
    CREATE OR REPLACE TRIGGER WTL_SMP_TRG2
    BEFORE UPDATE ON WTL_SAMPLES
    FOR EACH ROW
    DECLARE
         sampleCount NUMBER(1) := 0;
         dupLabSampleID NUMBER(8) := 0;
    BEGIN
         SELECT COUNT(sample_ID)
         INTO sampleCount
         FROM wtl_samples
    WHERE jb_job_id = :new.jb_job_id
    AND lab_no = :new.lab_no
         AND sample_ID != :old.sample_ID;
         IF sampleCount > 0 THEN
         SELECT sample_ID
         INTO dupLabSampleID
         FROM wtl_samples
         WHERE jb_job_id = :new.jb_job_id
         AND lab_no = :new.lab_no
              AND sample_ID != :old.sample_ID;
    RAISE_APPLICATION_ERROR(-20501, 'Update failed, Lab Number ' || :new.lab_no || ' is used by SampleID: ' || dupLabSampleID);
    END IF;
    --EXCEPTION
    --     WHEN OTHERS THEN
    -- RAISE_APPLICATION_ERROR(-20901, 'Error in WTL_SMP_TRG2.');
    END WTL_SMP_TRG2;
    any help appreciated
    adam

    I guess I couldve done that, but was using design editor and didn't know how to put a unique constraint in. Is the problem only because I'm referencing the :old.sample_ID, or the :new values as well? If it's just the :old value I could write a before update statement trigger to place the sample_id into a package varaible and then call that variable up in the row level trigger.... i've tried this, but don't know how to pull the sample_id value i need in the before statement trigger... i'll supply the code i've done so far...
    CREATE OR REPLACE TRIGGER WTL_SMP_TRG2_INIT
    BEFORE UPDATE ON WTL_SAMPLES
    DECLARE
    BEGIN
         wtl_trg_custom_pkg.oldSampleID := sample_id; /* Doesn't know sample_id...? */
    END WTL_SMP_TRG2_INIT;

  • Trigger without Mutating Problem - Urgent

    Hi,
    How should I create a trigger to fulfil the following business rule, without end up in Mutating problem,
    I have the following Table
    CREATE TABLE COMPCV
    COMPNO VARCHAR2(4) NOT NULL,
    ACCNO VARCHAR2(15) NOT NULL,
    ADDRES1 VARCHAR2(30),
    ACTIVE VARCHAR2(1)
    CREATE UNIQUE INDEX COMPCVIDX ON COMPCV (COMPNO,ACCNO)
    We have 5 different Companies (COMPNO = HO,OFF1,OFF2,OFF3,OFF4). The COMPNO & ACCNO should be Unique. So we have Unique Index Created.
    Every time when a Vendor is created in one of the Company, then it will need to reflect in ALL other companies.
    i.e. If a vendor is created in HO, it needs to reflect in OFF1, OFF2, OFF3 and OFF4.
    If a vendor is created in OFF1, it needs to reflect in HO, OFF2, OFF3 and OFF4 and so on.
    Hope it is clear.
    Thanks in advance
    Regards
    Murali

    Hi all,
    Thanks for all the inputs.
    Each Company is a different Entity and they operate from different locations. But the database is common. When a Vendor is Created in One Company say (COMPNO = HO), we want that information (vendor data) to be created automatic for all the other Companies ( FOR COMPNO = OFF1, OFF2,OFF3,OFF4).
    When a New Vendor is Created through the application (VB), we can duplicate the inserts into other companies as suggested. But if we could handle this thru DB Trigger, we don't need to create a new exe and install it in all the different PC in all the locations.
    Sample Data:
    Example if a Vendor is created in HO
    compno accno addres1 active
    ===========================
    HO V001 XYZ Y
    We want this to be created in other companies also like:
    OFF1 V001 XYZ Y
    OFF2 V001 XYZ Y
    OFF3 V001 XYZ Y
    OFF4 V001 XYZ Y
    Hope this clear.
    Best Regards
    Murali

  • How to avoid mutating error when insert or update record

    Hi ,
    I have one transaction table which is having some detail record under one transaction number, after the one transaction number is over by insert or update, i
    want to check the total amounts of one flag should be matched on same table if it is not then give error message. But i am getting mutating error on insert or update event trigger on statement level trigger on above table.
    Is there any other way to avoid mutating error to solve the above problem or some temp table concepts to be used. help me its urgent.
    Thanks in advance,
    Sachin Khaladkar
    Pune

    Sachin, here's as short of an example as I could come up with on the fly. The sample data is ficticious and for example only.
    Let's say I need to keep a table of items by category and my business rule states that the items in the table within each category must total to 100% at all times. So I want to insert rows and then make sure any category added sums to 100% or I will rollback the transation. I can't sum the rows in a row-level trigger because I'd have to query the table and it is mutating (in the middle of being changed by a transaction). Even if I could query it while it is mutating, there may be multiple rows in a category with not all yet inserted, so checking the sum after each row is not useful.
    So here I will create;
    1. the item table
    2. a package to hold my record collection (associative array) for the trigger code (the category is used as a key to the array; if I insert 3 rows for a given category, I only need to sum that category once, right?
    3. a before statement trigger to initialize the record collection (since package variables hang around for the entire database session, I need to clear the array before the start of every DML (INSERT in this case) statement against the item table)
    4. a before row trigger to collect categories being inserted
    5. an after statement trigger to validate my business rule
    I then insert some sample data so you can see how it works. Let me know if you have any questions about this.
    SQL> CREATE TABLE item_t
      2   (category  NUMBER(2)   NOT NULL
      3   ,item_code VARCHAR2(2) NOT NULL
      4   ,pct       NUMBER(3,2) NOT NULL);
    Table created.
    SQL>
    SQL> CREATE OR REPLACE PACKAGE trg_pkg IS
      2    TYPE t_item_typ IS TABLE OF item_t.category%TYPE
      3      INDEX BY PLS_INTEGER;
      4    t_item       t_item_typ;
      5    t_empty_item t_item_typ;
      6  END trg_pkg;
      7  /
    Package created.
    SQL> SHOW ERRORS;
    No errors.
    SQL>
    SQL> CREATE OR REPLACE TRIGGER item_bs_trg
      2    BEFORE INSERT
      3    ON item_t
      4  BEGIN
      5    DBMS_OUTPUT.put_line('Initializing...');
      6    trg_pkg.t_item := trg_pkg.t_empty_item;
      7  END item_bs_trg;
      8  /
    Trigger created.
    SQL> SHOW ERRORS;
    No errors.
    SQL>
    SQL> CREATE OR REPLACE TRIGGER item_br_trg
      2    BEFORE INSERT
      3    ON item_t
      4    FOR EACH ROW
      5  BEGIN
      6    trg_pkg.t_item(:NEW.category) := :NEW.category;
      7    DBMS_OUTPUT.put_line('Inserted Item for Category: '||:NEW.category);
      8  END item_br_trg;
      9  /
    Trigger created.
    SQL> SHOW ERRORS;
    No errors.
    SQL>
    SQL> CREATE OR REPLACE TRIGGER item_as_trg
      2    AFTER INSERT
      3    ON item_t
      4  DECLARE
      5    CURSOR c_item (cp_category item_t.category%TYPE) IS
      6      SELECT SUM(pct) pct
      7        FROM item_t
      8       WHERE category = cp_category;
      9  BEGIN
    10    DBMS_OUTPUT.put_line('Verifying...');
    11    FOR i IN trg_pkg.t_item.FIRST..trg_pkg.t_item.LAST LOOP
    12      DBMS_OUTPUT.put_line('Checking Category: '||trg_pkg.t_item(i));
    13      FOR rec IN c_item(trg_pkg.t_item(i)) LOOP
    14        IF rec.pct != 1 THEN
    15          RAISE_APPLICATION_ERROR(-20001,'Category '||trg_pkg.t_item(i)||' total = '||rec.pct);
    16        END IF;
    17      END LOOP;
    18    END LOOP;
    19  END item_as_trg;
    20  /
    Trigger created.
    SQL> SHOW ERRORS;
    No errors.
    SQL> INSERT INTO item_t
      2    SELECT 1, 'AA', .3 FROM DUAL
      3    UNION ALL
      4    SELECT 2, 'AB', .6 FROM DUAL
      5    UNION ALL
      6    SELECT 1, 'AC', .2 FROM DUAL
      7    UNION ALL
      8    SELECT 3, 'AA',  1 FROM DUAL
      9    UNION ALL
    10    SELECT 1, 'AA', .5 FROM DUAL
    11    UNION ALL
    12    SELECT 2, 'AB', .4 FROM DUAL;
    Initializing...
    Inserted Item for Category: 1
    Inserted Item for Category: 2
    Inserted Item for Category: 1
    Inserted Item for Category: 3
    Inserted Item for Category: 1
    Inserted Item for Category: 2
    Verifying...
    Checking Category: 1
    Checking Category: 2
    Checking Category: 3
    6 rows created.
    SQL>
    SQL> SELECT * FROM item_t ORDER BY category, item_code, pct;
      CATEGORY IT        PCT
             1 AA         .3
             1 AA         .5
             1 AC         .2
             2 AB         .4
             2 AB         .6
             3 AA          1
    6 rows selected.
    SQL>
    SQL> INSERT INTO item_t
      2    SELECT 4, 'AB', .5 FROM DUAL
      3    UNION ALL
      4    SELECT 5, 'AC', .2 FROM DUAL
      5    UNION ALL
      6    SELECT 5, 'AA', .5 FROM DUAL
      7    UNION ALL
      8    SELECT 4, 'AB', .5 FROM DUAL
      9    UNION ALL
    10    SELECT 4, 'AC', .4 FROM DUAL;
    Initializing...
    Inserted Item for Category: 4
    Inserted Item for Category: 5
    Inserted Item for Category: 5
    Inserted Item for Category: 4
    Inserted Item for Category: 4
    Verifying...
    Checking Category: 4
    INSERT INTO item_t
    ERROR at line 1:
    ORA-20001: Category 4 total = 1.4
    ORA-06512: at "PNOSKO.ITEM_AS_TRG", line 12
    ORA-04088: error during execution of trigger 'PNOSKO.ITEM_AS_TRG'
    SQL>
    SQL> SELECT * FROM item_t ORDER BY category, item_code, pct;
      CATEGORY IT        PCT
             1 AA         .3
             1 AA         .5
             1 AC         .2
             2 AB         .4
             2 AB         .6
             3 AA          1
    6 rows selected.
    SQL>

  • What are the best coding technics which will avoid performance problems

    Hi Experts
    What are the best coding technics which are avoiding memory problems and performance problems
    Some times one of few reports are taking too much time to executing while handling large data.
    1.What are the best way to declare a internal table to avoid performance problems.
    2.what is the best way to process data.
    3.what is the best way to clear memory.
    Can you guys help me give some good suggestions for  writing better programs  to avoid performance problems.
    Thanks
    Sailu

    Hi,
    Check this link..[Please Read before Posting in the Performance and Tuning Forum Updated |Please Read before Posting in the Performance and Tuning Forum;
    Which will be the first thread in the Performance and Tuning Forum.
    Search the SCN first.

  • How to avoid performance problems in PL/SQL?

    How to avoid performance problems in PL/SQL?
    As per my knowledge, below some points to avoid performance proble in PL/SQL.
    Is there other point to avoid performance problems?
    1. Use FORALL instead of FOR, and use BULK COLLECT to avoid looping many times.
    2. EXECUTE IMMEDIATE is faster than DBMS_SQL
    3. Use NOCOPY for OUT and IN OUT if the original value need not be retained. Overhead of keeping a copy of OUT is avoided.

    Susil Kumar Nagarajan wrote:
    1. Group no of functions or procedures into a PACKAGEPutting related functions and procedures into packages is useful from a code organization standpoint. It has nothing whatsoever to do with performance.
    2. Good to use collections in place of cursors that do DML operations on large set of recordsBut using SQL is more efficient than using PL/SQL with bulk collects.
    4. Optimize SQL statements if they need to
    -> Avoid using IN, NOT IN conditions or those cause full table scans in queriesThat is not true.
    -> See to queries they use Indexes properly , sometimes Leading index column is missed out that cause performance overheadAssuming "properly" implies that it is entirely possible that a table scan is more efficient than using an index.
    5. use Oracle HINTS if query can't be further tuned and hints can considerably help youHints should be used only as a last resort. It is almost certainly the case that if you can use a hint that forces a particular plan to improve performance that there is some problem in the underlying statistics that should be fixed in order to resolve issues with many queries rather than just the one you're looking at.
    Justin

  • Facing Problem in DB Trigger

    Hello Friends,
    I wrote the database trigger which executes when the db is up but it's not happen and i'm not able to find out the exact problem that the trigger is not exceutin or the problem in the job which is written inside the trigger.
    CREATE OR REPLACE TRIGGER FICREPORTS.trg_reporting
    AFTER STARTUP ON DATABASE
    WHEN (TO_CHAR (SYSDATE, 'D') <> '1')
    DECLARE
    v_currdate DATE := SYSDATE;
    BEGIN
    DBMS_JOB.isubmit (101,
    'begin proc_reportingstatus; end;',
    TO_CHAR (TRUNC(SYSDATE)+15/48,'dd-mon-rr hh:mi:ss') ,
    TO_CHAR (TRUNC(SYSDATE+1)+15/48,'dd-mon-rr hh:mi:ss')
    END trg_reporting;
    Kindly help.
    With Regards,
    Anand

    I advice you to create a table and insert a row in it after BEGIN
    CREATE TABLE test (ddate date);
    and after begin :
    BEGIN
    INSERT INTO test VALUES(sysdate);
    DBMS_JOB .....
    If there'll be a row in the table test, then your trigger is working and you've problem in your job

  • How to solve mutation problem

    how to solve the mutation problem in triggers
    Could you please guide me the steps to solve this

    Don't select from the same table in the trigger.
    (I'm pretty sure, it is not needed.)
    Think about your logic again, in most cases the trigger is the wrong approach.
    Tell us, what your business requirement is; what you are going to solve with a trigger.

  • Can I avoid this problem?

    Hi all,
    I made a game by flash and projected it into .exe file. It
    runs correctly excepte one thing.
    In this game, I used onEnterFrame and setInterval to make
    counters to coundown and do something.
    But when player holds down the movie's title bar by pressing
    down the right mouse button, the movie stops redrawing.
    So onEnterFrame and setInterval stop doing their jobs.
    Does anyone know how to avoid this problem?

    HI ,
    can anyone help me?
    I am confused whit this problem for a long time.

  • Hello, i restored and updated my iphone 4 to the latest version of 5.1.1 and after that when i connect my mobile to i tunes all i see is a big rectangle and a apple logo on left and a small lock on right side please help me fix this problem.

    hello,
    i restored and updated my iphone 4 to the latest version of 5.1.1 and after that when i connect my mobile to i tunes all i see is a big rectangle and a apple logo on left and a small lock on right side please help me fix this problem.

    I sloved this issue by resting my phone from settings>general>reset>reset all settings...the problem will be fixed

  • Please help me with Bios problem

    I have laptop toshiba Satellite L735-S9311D.
    I used windows service station and update bios to the latest version  during installion I forgot to unplug my external HDD.
    Error message appeared , Now no display on the screen.
    So, Please I need help to solve my problem.

    Please..............

  • Hi I've a big problem with adobe acrobat reader XI pro and I hope you can help me. The problem is; when I past copied text from some pdf books (not all of them) it past symbols only! wherever I past it! and even if I coped that text from another pdf reade

    Hi
    I've a big problem with adobe acrobat reader XI pro and I hope you can help me.
    The problem is; when I past copied text from some pdf books (not all of them) it past symbols only! wherever I past it! and even if I coped that text from another pdf reader (adobe pdf reader, internet browsers, ...etc.).
    This problem started to happen since yesterday when I installed adobe acrobat reader XI pro to try it before I buy it, and before that when I was using the free adobe pdf reader I was totally able to copy any text from any pdf and past it anywhere with nothing wrong.
    What can I do?
    thank you a lot.

    There is no product called Adobe Acrobat Reader Pro. There is
    - Adobe Acrobat Pro ($$)
    - Adobe Reader (free)
    Which do you have? And are you a programmer?

  • Can anyone help me with a problem i am having with my music on my iPhone 4S. I have put alot of Compilation CDs in my library on iTunes. I download these tracks onto my phone, everything is ok so far. Now, this is what is niggling me and I don.t know how

    Can anyone help me with a problem i am having with my music on my iPhone 4S. I have put alot of Compilation CDs in my library on iTunes. I download these tracks onto my phone, everything is ok so far. Now, this is what is niggling me and I don.t know how to resolve it. This is my problem: 
    Have downloaded for example: Queen – Bohemium Rhapsody from a compilation album as well as a few complete Queen Album CDs into the iTunes library and then put them into playlists,
    When I go onto my phone and select Queen on the MUSIC app using Songs tab at the bottom of the screen it will display all Queen songs and their resective Alum pics, that is all those not in a complilation album, .
    If I know the song title I can select the songs tab and find the song that way,
    I’ve tried fiddling with the settings in the iTunes app by going to ‘get info’ tab and trying to sort the problem out that way but am not having much luck.What I want the phone to do is show, for example all Queens songs including those in compilation albums. Can this be done, would be grateful for any ideas on how it can be done, that is if ic can be done, any ideas
    Thanks for your help

    Try assigning Queen as the Album Artist on the compilations in iTunes on your computer.

  • Tabs only open in a new window. Ctl T opens a new window NOT a new tab help-last update this problem started. How do I set FF back to open tabs in 1 window

    Tabs only open in a new window. Ctl T opens a new window NOT a new tab help-last update this problem started 2 days ago. How do I set FF back to open tabs in 1 window?
    There is no plus sign and going into optins and changing settings has not worked. I have uninstall FF and reinstall-keeping my personalization-and that was no help.
    Right clicking on FF Icon to open a new tab, or going up to FF drop down tab and clicking on new tab both do not work.
    Help everything opens a new window not a new tab. there seems to be no way to reset this or to chose a different optin. I just downloaded new tabs at end addon and it didn't do a thing.

    as a first troubleshooting step - does it work like normally when you open & run firefox in [[Safe Mode|safemode]] by pressing the shift key while you open firefox (all other instances have to be closed before)...

  • HT204088 Dear sirs,  Could you please help me on my problem with my apple ID  I create new account with security questions, and when I try to purchase paid application,it ask me for answers the questions but it's not working,  My account have 50$ and stil

    Dear sirs,
    Could you please help me on my problem with my apple ID
    I create new account with security questions, and when I try to purchase paid application,it ask me for answers the questions but it's not working,
    My account have 50$ and still didn't buy anything

    You need to ask Apple to reset your security questions; ways of contacting them include clicking here and picking a method for your country, phoning AppleCare and asking for the Account Security team, and filling out and submitting this form.
    (100546)

Maybe you are looking for

  • Free goods - reg

    hi gurus,        i have reqt i.e, when the customer any two materials, the company want to give the third material at free of cost. for this wat is the configuration. regards, krish.

  • Search help in dialog program

    Hi all, Fora search help in dialog program. I HAVE TO GET SEARCH FOR A FIELD ZID ON APARTICULAR SCREEN BASED ON DATA, MODIFIED BY AND A PLANT.. I HAVE A RECORD IN ONE MY ZTABLE. I HAVE TO GET THAT BY SEVERAL SEARCH PARAMETERS SAY BY DATE , MODIFIED B

  • Getting ServletRequest in a JSP page?

    Sorry about the newbie question, but how do you access the ServletRequest object in a JSP page? Specifically, the getParameter() functions? In servlets it's easy, the objects are passed in the doget() and dopost() functions, but I have no clue how to

  • Hashmap in Hashmap as Key?

    Can anybofy let me know, what could be the possible disastrous outcome of keeping Hashmap in Hashmap as Key? Could it lead to inconsistent behaviour? If its not a good idea to use Hashmap as key in a Hashmap what other data structure we can use for t

  • Host package mirror

    Hi I have a server with more storage than I need and an internet connection of 1000/1000. I was thinking about setting it up as a mirror for pacman. It has an  Intel Core i7 2600K, 16 GB ram and a 4TB RAID 10. All its doing now is hosting a webserver