Update trigger ...problem

... i have following requirement for the update of person table
1) if address field is changed then i want to store old address information in one table and then replace the new address in person table
2) if fields other than address are changed then just new values get replaced in person table... ne need of storing old values any where...
how can i do that any idea..

There are two ways to do it, database triggers or form level triggers.
For database, u have to create a trigger on the table which will be executed only when the address field is updated, for example,
CREATE
TRIGGER <trigger_name>
BEFORE UPDATE OF <table_column> ON <table_name>
REFERENCING OLD AS old NEW AS new
FOR EACH ROW
BEGIN
do the right thing.......
insert into the old value in other table......
assign new values to the old one.........
END;
or u can use the on-, pre- or post update trigger at the form level after checking if the address field is changed and updated. See forms help for Get_item_property built-in Database_value.
Message was edited by:
zaibiman

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;

  • Can any one please send me an update trigger (pl/sql procedure) for ap tables(ap_suppliers,ap_supplier_site_all,and contacts)

    Please send an query for update trigger for those tables .
         1: ap_suppliers
         2: ap_supplier_sites_all
         3: ap_supplier_contacts.
    Thanks,
    Chaitanya.

    Hi,
    Actually ID and Data are different names in my API. Here I mentioned like that.
    Am using Oracle 10g version.
    Yes I am going to get the multiple values using this Ref Cursor. The same ref cursor is used in another API of my package.
    In this API, the user actually enters Application_id and data. API should insert/update the version_master table with the inputs. See application_id is the foriegn key for app_master table.
    The requirement is whenever they enters application_id and data, if application_id already present in the version_master table, then the data should be updated and we should get a status flag for this using Out variable(i.e. using ref cursor only we are showing the status). if the application_id is not present in the version_master table, new record should be inserted. The sequence will generate the version_id for version_master table.
    But the Merge statement is working fine for update and insert also. Problem is am unable to see the success or failure through ref cursor. I don't know how exactly I can use this.
    If data is NULL the operation should be failed. i.e. I should get Failure status here. But am not getting this.
    Please remove the comments here and then check. If I use the NVL2 function I was able to get the status flag, i.e. S or F.
    OPEN resultset_o FOR
    SELECT NVL2 (data, 'S', 'F')
    FROM version_master
    WHERE application_id = application_id_i;
    1.How the value of data being not null will determine Success of the api and how null failure
    2.If the above select statement goes in to exception when others how I will no the failure
    I have to achieve the above scenarios.
    Please advice me.

  • Update trigger is not working...

    Hi
    I am writing an update trigger.
    We have a two DB, one is application DB and other is reporting DB. We are writing trigger on Reporting DB. There is a job schedule for synchronizing the application data to reporting DB , this daly basis synchronization. So when the synchronization runs and if the FUNDING_RULE_TABLE is updated them my trigger gets called.
    CREATE OR REPLACE
    TRIGGER COMM_EXISTING_REP_TRIGGER AFTER UPDATE OF FR_IR_NAME ON FUNDING_RULE_TABLE
    DECLARE
    serialno INTEGER;
    CURSOR C_CES_REP IS
    Select distinct FR_IR_NAME,FR_IR_CODE from FUNDING_RULE_TABLE ;
    V_IR_NAME FUNDING_RULE_TABLE.FR_IR_NAME%TYPE;
    V_IR_CODE FUNDING_RULE_TABLE.FR_IR_CODE%TYPE;
    CURSOR C_CES_COMIT IS
    SELECT DISTINCT FR_IR_NAME1,FR_IR_CODE from COMM_EXSTS_COMIT_AGGR;
    IR_NAME VARCHAR2(20);
    IR_CODE VARCHAR2(10);
    BEGIN
    OPEN C_CES_REP;
    LOOP
    FETCH C_CES_REP INTO V_IR_NAME,V_IR_CODE;
    IF C_CES_REP%NOTFOUND THEN
    EXIT;
    END IF;
    OPEN C_CES_COMIT;
    LOOP
    FETCH C_CES_COMIT INTO IR_NAME,IR_CODE;
    IF(V_IR_CODE = IR_CODE AND V_IR_NAME = IR_NAME) THEN
    EXIT;
    ELSE
    update COMM_EXSTS_COMIT_AGGR set FR_IR_NAME1 = IR_NAME where FR_IR_CODE = IR_CODE;
    END IF;
    END LOOP;
    CLOSE C_CES_COMIT;
    END LOOP;
    CLOSE C_CES_REP;
    END COMM_EXISTING_REP_TRIGGER;
    The problem is:
    When the synchronization runs the trigger will gets called and the synchronization prc never stops because of the table locks.
    1)     why some tables are getting locks? (I think this is becuse some source is waiting for another to release-deadlock)
    2)     Is there any problem in trigger? (I think there is some problem is trigger)
    3)     When I comment below part then sync procedure works fine
    OPEN C_CES_COMIT;
    LOOP
    FETCH C_CES_COMIT INTO IR_NAME,IR_CODE;
    IF(V_IR_CODE = IR_CODE AND V_IR_NAME = IR_NAME) THEN
    EXIT;
    ELSE
    update COMM_EXSTS_COMIT_AGGR set FR_IR_NAME1 = IR_NAME where FR_IR_CODE = IR_CODE;
    END IF;
    END LOOP;
    CLOSE C_CES_COMIT;
    It menas that there is somr problem in trigger because i am reading and updation is performed on the same table "COMM_EXSTS_COMIT_AGGR ".
    Is this is the problem?
    waitting for ur rply...thx..
    Edited by: 931005 on Apr 30, 2012 2:38 AM

    Welcome to the forum!
    Whenever you post provide your 4 digit Oracle version (result of SELECT * FROM V$VERSION).
    >
    1) why some tables are getting locks? (I think this is becuse some source is waiting for another to release-deadlock)
    >
    Because you have an UPDATE statement in your inner loop that may lock one or more rows that are updated.
    >
    2) Is there any problem in trigger? (I think there is some problem is trigger)
    >
    Many problems
    1. The outer query queries the same table that the update trigger is updating. So some rows may never get seen; rows inserted or updated by other sessions. This means the DISTINCT results may not be distinct at all.
    2. The cursors select into SCALAR variables so if either cursor returns more than one row the trigger will raise an exception.
    3. The nested cursor loops could be replaced by a simple update statement.
    4. The original issue of updating the same table queried by your cursor.
    Whatever it is you are trying to do - this isn't the way to do it.

  • After Update Trigger executes twice when single row is uptd thro proc

    We have the below trigger in our db. When a single record is updated using a procedure the trigger is executed twice and it inserts two records in other table.
    But when i issue an update statement using any sql client tool it is executing only once and inserts only one record in other table.
    Can any one please help me to find the reason?
    Trigger:*
    create or replace TRIGGER CX_HEADER_ESCL_T1 AFTER UPDATE OF STATUS ON CX_HEADER
    FOR EACH ROW
    DECLARE
    "b1-CTRIYJ" boolean := FALSE;
    BEGIN
    IF UPDATING('STATUS') AND(:NEW.status = 'SUCCESS') THEN
    "b1-CTRIYJ" := TRUE;
    END IF;
    IF "b1-CTRIYJ" = TRUE THEN
    INSERT
    INTO siebel.s_escl_req(req_id, created, bt_row_id, rule_id, tbl_name, created_by, group_id)
    VALUES('11111111', CURRENT_DATE, :NEW.row_id, '1-CTRIYJ', 'CX_HEADER', :NEW.last_upd_by, '1-2CU3');
    "b1-CTRIYJ" := FALSE;
    END IF;
    END;
    Procedure:
    CREATE OR REPLACE
    PROCEDURE CLOSE_BATCH
    (ChildRecordCount IN NUMBER, HeaderId IN VARCHAR2, CompletionStatus OUT VARCHAR2) AS
    CafeChildCount NUMBER;
    BEGIN
    select count(*) into CafeChildCount from SIEBEL.CX_CHILD where HEADER_ID=HeaderId;
    IF ChildRecordCount = CafeChildCount THEN
    update SIEBEL.CX_HEADER set STATUS ='SUCCESS', MODIFICATION_NUM = MODIFICATION_NUM+1 where HEADER_ID=HeaderId;
    CompletionStatus := 'SUCCESS';
    ELSE
    update SIEBEL.CX_CHILD set STATUS='FAILED' where HEADER_ID=HeaderId;
    update SIEBEL.CX_HEADER set STATUS='FAILED' where HEADER_ID=HeaderId;
    CompletionStatus := 'FAILED';
    END IF;
    commit;
    /*CompletionStatus := 'SUCCESS';*/
    EXCEPTION
    WHEN OTHERS THEN
    CompletionStatus := SQLCODE;
    rollback;
    END;

    Your problem seems not be related to the trigger restart issue I have already mentioned because you are using a AFTER UPDATE trigger and not a BEFORE UPDATE trigger:
    >
    BEFORE Triggers Fired Multiple Times
    If an UPDATE or DELETE statement detects a conflict with a concurrent UPDATE, then Oracle Database performs a transparent ROLLBACK to SAVEPOINT and restarts the update. This can occur many times before the statement completes successfully. Each time the statement is restarted, the BEFORE statement trigger is fired again. The rollback to savepoint does not undo changes to any package variables referenced in the trigger. Your package should include a counter variable to detect this situation.
    >
    If you are sure that you update a single row and that your trigger fires twice and if you can easiily reproduce the issue, I recommend that you contact Oracle Support and create a Service Request for your issue that could be an Oracle bug.

  • Update Trigger and COLUMNS_UPDATED()

    Let me rephrase my question:
    I want to know if there is a faster way (probably using bit operators) to see if COLUMNS_UPDATED() in an update trigger on a table with more than 8 columns contains any column other than 1 specific column I will refer
    to as 'columnToIgnore'. I don't care about which columns are included or if the value has actually changed, only that there are other columns present.
    Original question:
    I have inherited a Sql Server database + schema and corresponding application and I have been tasked with speeding up the batch update of users in the database. After running some profiling I discovered that the reason it was slow is because of an update
    trigger on the users table. I did some “cleaning up” of the trigger and now it runs faster but I still think it could be more efficient. The objective of the trigger is to write to an Audit table any time an update takes place and any column is updated (it
    does not actually matter if the value has changed or not) with the exception of 1 specific column. Now I have the following code in the trigger which I had refactored from something much uglier.
    DECLARE @ColumnsUpdated VARBINARY(100)
    SET @ColumnsUpdated = COLUMNS_UPDATED()
    DECLARE @onlyIgnoreColumnChanged int
    SET @onlyIgnoreColumnChanged = 1
    SET @onlyIgnoreColumnChanged = 1
    IF (EXISTS(SELECT 1
    FROM INFORMATION_SCHEMA.COLUMNS Field
    WHERE TABLE_NAME = 'users'
    AND sys.fn_IsBitSetInBitmask(@ColumnsUpdated, COLUMNPROPERTY(OBJECT_ID('dbo.users'), COLUMN_NAME, 'ColumnID')) <> 0
    AND column_name !='columnToIgnore')) BEGIN
    SET @onlyIgnoreColumnChanged = 0
    END
    Ideally I would change the code to disable the trigger and do the insert myself BUT the code is old Classic ASP ( ie. VBScript with ODBC database connections) so I am not going to change any of the calling code because that would cost too much time and probably
    create more problems than I am solving.
    My proposed fix which I am unsure of how to code in SQL:
    It seems to me that there should be a way to get the proper id or position for the column and see if the column was used in the COLUMNS_UPDATED().
    If it was not used then we can set @onlynieuwchanged to 0 for the remaining code (not shown)
    If it was used then remove the bit from the COLUMNS_UPDATED() and see if it is empty
    If its empty then then we can set @onlynieuwchanged to 1 for the remaining code (not shown)
    If it’s not empty then then we can set @onlynieuwchanged to 0 for the remaining code (not shown)
    My problem is I am not sure how to go about coding this logic in SQL. I would think it would be possible with BIT operators? It would seem this could be more efficient than what I have now as it would get rid of the select statement which could slow down
    a large batch update.
    Notes
    My table has 30+ some columns so more than 8 which is relevant when working with COLUMNS_UPDATED() from what I have read. It also means that testing each column with UPDATE() would probably be more inefficient than what I have now.
    The update is called from the front end code (VBScript) which currently times out although not as much as it used to with my latest change. I cannot alter the code to run async mode and show progress, it would be easier for me to update the trigger.
    Reason for audit - we only record the user id in an audit table. This is then used to force a sync to another system outside of our source control that is used for various other tasks (mailings, views, etc). Again, I do not want to change how this system
    works, I only want to speed up the existing trigger with minimal effort.
    Sql Server version 2012, database Schema is set to Sql server 2005 compatibility mode.
    Any help would be greatly appreciated. Thank you in advance!
    -Igor

    Thank you again everyone for your input. As I mentioned there is much out of my control. This is an active application worked on by many developers and has been pieced together over the past 10+ years. It is NOT well written, the database schema has MUCH
    to be desired, and the code is the classic definition of 'spaghetti' code and multiple platforms are used to access the data, and there are millions of lines of code. There is nothing I can do about all of this which is why I am ignoring much of the advice.
    Sure, if this was a new application or something that was well written and possible to do some modifications then I would BUT it's not. If I was given 1 year of dedicated time to fix everything... well, I would probably throw it all away and start from scratch.
    Here is what I finally came up with. It is probably not  much faster, if at all, but when I started this I thought there would be a simple solution that I did not see. I will probably leave my code the way it was but will include the following for reference.
    DECLARE @bit int, @field int, @char int, @comparisonField VARBINARY(100)
    -- the following segment recreates the value contained in COLUMNS_UPDATED() if only the field nieuw was altered and stores that value in field @comparisonField
    SET @field = (SELECT COLUMNPROPERTY(OBJECT_ID('dbo.users'), 'columnToIgnore', 'ColumnID')) -- geth the field id for column nieuw
    select @bit = (@field - 1 )% 8 + 1
    select @bit = power(2,@bit - 1)
    select @char = ((@field - 1) / 8) + 1
    -- select @field AS [Field number], @char AS [Char], @bit AS [Bit] -- debug code to check the bits that are tested.
    -- Recreate the binary value of just having the field present in the columns_updated
    SELECT @comparisonField = CONVERT(VARBINARY(100),'0x' + RIGHT('000000000000000000' + RIGHT(CONVERT(VARCHAR(30), CONVERT(varbinary(1), @bit), 1), 2), @char*2), 1)
    -- if the generated value in @comparisonField is the same as COLUMNS_UPDATED() then only nieuw was updated
    IF @comparisonField <> COLUMNS_UPDATED() BEGIN
    -- code to add to the tracking table
    END
    -Igor

  • How to activate JDBC debugging for SPRING 3.1? Oracle trigger problems ...

    Hi,
    I have some trigger problems. I created a trigger to update a certain column each time a new record is inserted or an existent record is updated. I use Oracle 10g. If I create the trigger and execute an insert query via the XE client everything works fine. However, when I use a spring 3.1 setup with Hibernate and OJDBC driver, I get an
    java.sql.SQLException: ORA-04098: trigger 'LOCALUSER_PROP_TRIG' is invalid and failed re-validation
    And if I execute a show error trigger query I get an invalid SQL query error.
    I can easily activate Hibernate debugging and I can see that the prepared statement by Hibernate is just fine, but I was wondering if I could see the full sql sent by the JDBC driver to the server. Maybe seeing the actual query sent to the server would provide new insight of what could be wrong in the Hibernate setup. Does any one what could be wrong and eventually how could setup jdbc to output debug info? Thanks a lot,
    Cristian

    Which platform is the database running on ??
    Other things you should check -
    when debugging the EJB, JDev
    3.1 looks through your IIOP connections to find the one to use.
    Make sure that the IIOP connection that JDev is using for the debugging matches the IIOP connection that the EJB client application is using.
    raghu
    null

  • Instead of update trigger

    Hi
    I have a view, I like to create a update form for.
    Someone have a sample how to use a "instead of update trigger" with a form?
    I would like to have a report with a column link to the form, and the form use a "instead of update trigger" to update the row.
    Best Regrads
    Jesper Vels

    Hi Jesper,
    <p>I'm not sure I understand your problem correctly but I'll have a go nevertheless.</p>
    <p>I think you can accomplish this with standard out of the box apex functionality. </p>
    <p>You can create your report with a link to your data entry form which has auto DML functionality built in. I do not understand the need for an update trigger, based on what you have said. </p>
    <p>I think this link will give you an idea how how to accomplish the functionality your looking for.</p>
    <p>Otherwise In version 2.0 (the only version I have access to at the moment - though should be the same in 2.2). Create a new page of type form and specify "Form on a Table with Report" in the next stage of the wizard. Work through the rest of the wizard and see whether what is generated fits your purpose or can easily be adapted to suite your purposes. </p>
    <p>Let me know how you get on.</p>
    <p>Regards
    Kris
    </p>
    Regards Kris

  • Update/Insert Problem with Oracle Warehouse Builder

    Hello,
    i have update/insert problem with owb.
    Situation: I have a source-table called s_account and a target table called w_account_d. In the target table are already data which was filled trough the source table inserts. Now anyone make changes on data on the target table. This changes should now give further on the source table with an update operation. But exactly here is the problem i can´t map back the data to source because that will create a loop.
    My idea was to set a trigger but i can´t find this component in owb or is anywhere hidden?
    Also i have already seen properties as CDC or conditonal loading in the property inspector of the table, but i have no idea how it works.
    Give it other possibilities to modeling this case? or can anyone me explain how i can implement this eventually with CDC?
    I look forward for your replies :)

    Hi
    thanks for your answer. I follow your suggestion and have set the constraints of both tables into the database directly.Nevertheless it doesn´t work to begin. In the next step i found by right click on a table the listpoint "configure" - I goes to "unique key" --> creation method and set here follow options: Constraint State = ENABLE, Constraint Validation = Validate. That error message that appears before by the deployment disappears yet. Now i start the job to test if the insert/update process works right. Finally it seems to work - but not really.
    My Testscenario
    1. Load the data from source table about the staging area to data warehouse table: Check - it works!
    2. Change one data record in source table
    3. Load the source table with changed data record once again to staging area: Check - it works!
    4. Load new staging area table with the changed data record to data warehouse table: Check it works! BUT, BUT i can not recognize if it is insert or update operation, then under the design window by jobs execution windows is reported "rows selected 98", Rows inserted" is empty and "rows updated" is empty. So i think works not correct, then my opinion if it works correct it should show be "rows updated" 1.
    What can yet now still be wrong or forgotten? Any ideas?
    *By the way think not 98 rows there is not important if you make an update or insert which performance. It is an example table the right tables have million of records.*
    I look forward for your answers :)

  • DB Trigger Problem??

    Hi ,
    I have one problem :
    By using database trigger on EMP table I have to update the salary of all the subordinates by 10% if their Manager's Salary is incremented by 5%.
    I did it by using a package -that contains PL/SQL Table to store the Manager's Emp No those got increment and their old & new Salary.
    Before Update Trigger(Row-Level Trigger) to assign the values in the PL/SQL table. and
    After Update(statement Level Trigger)-That reads the manager's empno,old salary & new salary from PL/SQL table and update the EMP table for their Subordinates.
    But It gives me the Recursive SQl error.
    Pls Help Me ASAP
    Regards.
    Suneel

    There is a good reason for this behaviour. You are trying to automate something that probably shouldn't be automated. Consider:
    SELECT * FROM my_emp
    ID  JOB        MGR_FLAG  MGR  SAL
    1   PRESIDENT  Y              5000
    2   SALESMAN   Y         1    2500
    3   GRUNT      N         2    1400If I issue the following SQL :
    UPDATE my_emp
    SET    sal = sal*1.05
    WHERE  mgr_flag = 'Y'
    / what should happen? Well, employees 1 and 2 should get a 5% pay rise because they are managers. And employee 3 gets a 10% pay rise, because her manager got 5%. So far so cool. But hang on a moment, employee 2 is managed by employee 1 so, as employee 1 got a 5% pay rise, employee 2 is entitled to a 10% pay rise.
    Now, which order do these things get processed in? Because that might make a difference. As it happens, ((2500 * 1.05) * 1.10) = 2887.5 whereas ((2500 * 1.10) * 1.05) = 2887.5. So it doesn't make a difference, in this case.
    But Oracle doesn't know that. With a more complicated algorithm e.g.
    IF sal < 2700
    THEN sal := sal+100;
    ELSE sal := sal * 1.05; 
    END IF;the order the rows are processed in will make a difference. And because it is impossible to forecast beforehand in which order rows will get processed Oracle baulks. It only allows SQL which has predictable results.
    Furthermore, the logic is dubious. Is it right for employee 2 to receive two pay rises? Is it right for employee 3 to receive two pay rises as well?
    Sure, using AUTONOMOUS TRANSACTION will suppress the error message. But the logic of the design remains flawed. I hope you now understand why this is not a good idea.
    Cheers, APC

  • Mutating DB Trigger Problem

    Hello all, i have a ' Mutating DB Trigger Problem' for the following Trigger :
    =============================================
    CREATE OR REPLACE TRIGGER ASSIUT.EMP_ATTENDANCEE_MONA
    AFTER INSERT
    ON ASSIUT.ACCESSLOG
    REFERENCING NEW AS NEW OLD AS OLD
    FOR EACH ROW
    DECLARE
    V_COUNT CHAR(2);
    --V_COUNT_OUT CHAR(2);
    BEGIN
    IF :NEW.INOUT = 'IN' THEN
        INSERT INTO EMP_ATTENDANCEE (EMP_ID, DATE_IN ,DATE_OUT ,TIME_IN ,TIME_OUT)
         VALUES (TO_NUMBER(TO_CHAR(:NEW.employeeid,99999)),
                 TO_DATE(:NEW.LOGDATE,'dd/mm/rrrr'),       -- DATE_IN
                 NULL,
                 TO_DATE(:NEW.LOGTIME,'HH24:MI:SS'),      -- TIME_IN
                 NULL );      -- TIME_OUT
                     SELECT COUNT(employeeid )
                     INTO V_COUNT
                    FROM ACCESSLOG
                    WHERE employeeid =:NEW.employeeid
                    AND LOGDATE =:NEW.LOGDATE
                    AND  LOGTIME  =:NEW.LOGTIME
                    AND INOUT ='IN';
                    IF V_COUNT > 0 THEN
         INSERT INTO ATT_INCOMPLETE  (  EMP_ID , ATT_DATE , ATT_TIME ,  ATT_FLAG)
         VALUES (TO_NUMBER(TO_CHAR(:NEW.employeeid,99999)),
                 TO_DATE(:NEW.LOGDATE,'dd/mm/rrrr'),       -- DATE_IN
          TO_DATE(:NEW.LOGTIME,'HH24:MI:SS'),        -- TIME_IN
          1); -- check in
          END IF;
    ELSIF :NEW.INOUT = 'OUT' THEN
        UPDATE  EMP_ATTENDANCEE
        SET           DATE_OUT   =  TO_DATE(:NEW.LOGDATE,'dd/mm/rrrr'), -- DATE_OUT,
                      TIME_OUT   =   TO_DATE(:NEW.LOGTIME,'HH24:MI:SS') -- TIME_OUT
        WHERE   EMP_ID           =   TO_NUMBER(TO_CHAR(:NEW.employeeid,99999))
        AND DATE_IN =  (SELECT MAX (DATE_IN )
                        FROM EMP_ATTENDANCEE
                        WHERE EMP_ID = EMP_ID
                        AND   DATE_OUT IS NULL
                        AND   TIME_OUT IS NULL ) ;
                  SELECT COUNT(employeeid )
                     INTO V_COUNT
                    FROM ACCESSLOG
                    WHERE employeeid =:NEW.employeeid
                    AND LOGDATE =:NEW.LOGDATE
                    AND  LOGTIME  =:NEW.LOGTIME
                    AND INOUT ='OUT';
                    IF V_COUNT > 0 THEN
    INSERT INTO ATT_INCOMPLETE  (  EMP_ID , ATT_DATE , ATT_TIME ,  ATT_FLAG)
         VALUES (TO_NUMBER(TO_CHAR(:NEW.employeeid,99999)),
                 TO_DATE(:NEW.LOGDATE,'dd/mm/rrrr'),       -- DATE_IN
          TO_DATE(:NEW.LOGTIME,'HH24:MI:SS'),        -- TIME_IN
         0); -- check in
    END IF;
    END IF;
      EXCEPTION
       WHEN OTHERS  THEN RAISE;
    END EMP_ATTENDANCEE_MONA ;The above Trigger generates the following error:
    ORA-04091: table ASSIUT.ACCESSLOG is mutating, trigger/function may not see it
    ORA-06512: at "ASSIUT.EMP_ATTENDANCEE_MONA'", line 65
    ORA-04088: error during execution of trigger 'ASSIUT.EMP_ATTENDANCEE_MONA'i want an easy and a straight forward solution to this problem which occured on selecting or manipulating from the same table i triggered it.
    Best regards,
    Abdetu..

    Create a package
    CREATE OR REPLACE PACKAGE PK_TRIGGER IS
      PROCEDURE PR_BS;
      PROCEDURE PR_ARIU(i_vcType IN TABLE.COLUM%TYPE, i_nEmpId TABLE.COLUM%TYPE, i_vcLogDate IN TABLE.COLUMN%TYPE, i_vcLogTime IN TABLE.COLUMN%TYPE);
      PROCEDURE PR_AS;
    END;
    CREATE OR REPLACE PACKAGE BODY IS
      TYPE tData IS RECORD (
        vcType     TABLE.COLUMN%TYPE,
        nEmpid     TABLE.COLUMN%TYPE,
        vcLogDate TABLE.COLUMN%TYPE,
        vcLogTime TABLE.COLUMN%TYPE
      TYPE tDataList IS TABLE OF tData INDEX BY BINARY_INTEGER;
      lData tData;
      PROCEDURE PR_BS IS
      BEGIN
        lData.DELETE;
      END;
      PROCEDURE PR_ARIU(i_vcType IN TABLE.COLUM%TYPE, i_nEmpId TABLE.COLUM%TYPE, i_vcLogDate IN TABLE.COLUMN%TYPE, i_vcLogTime IN TABLE.COLUMN%TYPE) IS
        iPos PLS_INTEGER:=lData.COUNT+1;
      BEGIN
        lData(iPos).vcType:=i_vcType;
        lData(iPos).nEmpId:=i_nEmpId;
        lData(iPos).vcLogDate:=i_vcLogDate;
        lData(iPos).vcLogTime:=i_vcLogTime;
      END;
      PROCEDURE PR_AS IS
        CURSOR crCheck(i_nIdentnum IN NUMBER) IS
          SELECT 1
            FROM <YOURTABLE> A,
                 <YOURTABLE> B
           WHERE A.IDEN_NUM=B.IDENT_NUM
             AND (   A.BEGIN_DATE BETWEEN B.BEGIN_DATE AND B.END_DATE
                  OR A.END_DATE BETWEEN B.BEGIN_DATE AND B.END_DATE
        iPos PLS_INTEGER;
        nDummy NUMBER;
      BEGIN
        iPos:=lData.FIRST;
        LOOP
          EXIT WHEN iPos IS NULL;
          -- Do whatever you want with the data in the record
          -- Process next record
          iPos:=lIds.NEXT(iPos);
        END LOOP;
        lIds.DELETE;
      END;
    END;replace TABLE.COLUM%TYPE with appropiate table and column
    Now create a
    - Before Statement trigger on your table calling PK_TRIGGER.PR_BS;
    - After Insert on Update for each row Trigger calling PK_TRIGGER.PR_ARIU(...values...);
    - After Statement trigger on your table calling PK_TRIGGER.PR_AS;
    Hope the code compiles for i have no database at hand.
    Andreas

  • After Update Trigger issue

    Hello,
    I am having a problem with after update trigger. I have created an after update trigger in Oracle that would call a procedure to run an Oracle report. The problem is that when the report is run, the table is not updated yet. So the table passes old values to the report. Is there any way I can take care of this issue? How do I make sure the table is updated before running the report? I tried delaying the report by using dbms_job package. I didn't have any success with that. Probably I am doing something wrong. This is the code I used
    dbms_job.submit( job => l_job, what => 'SendPDFReport(:new.query_id,serviceid,:new.site_id);', next_date => sysdate+3/24*60 );
    Thanks
    Oracle database User

    It is working. I used the same code,but I was using parameters inside the single quote, so it was taking the parameter value as :new.query_id instead of 12345.
    I made changes
    from
    dbms_job.submit( job => l_job, what => 'SendPDF(:new.query_id,serviceid,:new.site_id);', next_date => sysdate);
    to
    dbms_job.submit( job => l_job, what => 'SendPDF('||:new.query_id||','||serviceid||','||:new.site_id||');', next_date => sysdate);
    Thanks for all your help.

  • Before update and after Update trigger

    Hi,
    I am following the below approach to overcome ORA-04091: table XXXX is mutating error.
    1. In the after update row level trigger i am capturing rowids of changed rows into a table type (of type rowid) defined in a package.
    2. In the after update statement level trigger i am using the data from the table type ( that got populated in the first step) to do my work.
    3. In the before update statement level trigger i am resetting the table type defined in the package.
    Now, can the below situation occur causing the system to fail
    1. A Update to the table occurred causing the before update statement level trigger to fire and reset the table type.
    2. After that row level after update trigger gets executed and captures the required data.
    3. Now before the after update statement level trigger gets executed a new update to the table happened ( to some other row as multiple users are using the application) causing the
    before update statement level to fire and erase the data from the table type?
    I want to know if above situation can occur or is the execution or before and after update triggers atomic?
    Thanks for helping.
    TIA
    Harsha

    A collection in a package is local to the session. And a given session can be processing one SQL statement at a time. So any concurrent updates would be happening in a different session with a different logical collection.
    You may encounter problems if your session is trying to update the same rows that other sessions are trying to update (whether via the original update statement or via the updates issued by the trigger). You could encounter performance problems because of row level locks or you could encounter deadlocks. But your session's collection won't be initialized by some other session's actions (other than DDL that replaced the package itself).
    Justin

  • How can I access the same table within AFTER UPDATE trigger?  mutating

    I'm trying to have processing done within a before or after update trigger.
    reduced what I want to do down to a select within the trigger.
    create or replace TRIGGER "AU_TABLE_A"
    after update on "TABLE_A"
    for each row
    declare
    l_res_status NUMBER:=0;
    l_count NUMBER:=0;
    begin
    SELECT COUNT(*) INTO l_count
    FROM TABLE_A
    WHERE ID = :NEW.ID AND STATUS_ID = 9;
    end;
    Error in mru internal routine: ORA-20001: Error in MRU: row= 1,
         ORA-04091: table TABLE_A is mutating, trigger/function may not see it
         ORA-06512: at "BHRS.BU_MR_RES_APPR", line 13
         ORA-04088: error during execution of trigger 'BHRS.BU_MR_RES_APPR',
         update TABLE_A set "ID" = :b1, "STATUS_ID" = :b2, "COMMENTS" = :b3
         where "ID" = :p_pk_col
    IS THERE A WAY AROUND IT?
    Thank you, Bill

    The very common approach to workaround mutating table problem is passing the table state through the package variables. I.e. - you create a package with one global variable ( say l_count). Then you need
    1) a trigger before update for statement - here you counts your rows and set the package variable accordingly.
    2) a trigger after update for each row - here you read the rowcount from a package variable and do your actual work
    3) a trigger after update for statement - here you reset your package variable.
    This approach uses the fact, that mutating table problem occurs only with triggers for each row and the order of execution of different trigger types.
    However, counting records in every update statement (whereas not so worse although as doing this for each row within an update) may consume a lot of resources, so, possibly , you can rethink your business needs/approach.
    Best regards
    Maxim

  • Slow update on 11g in conjuction with before update trigger

    Hello,
    I have strange problem - when on table exists before update trigger(in its body is nothing important, maybe problem is on other triggers aswell), then repeating update on this table is slower and slower on 11g, on 10g it is ok. Problem is on windows and linux platform aswell.
    I created some scripts to simulate this behavior, in table is 60 000 row. In one loop I update all 60 000 rows from table and measure time.
    Can someone tell me where problem is and if it is possible to manage it with some settings or anyway ? In our application it is big problem, similar operation takes days ......
    thanks tomas
    times for 10g:
    Trigger disabled
    Loop 1 - 6,13 secs
    Loop 2 - 2,92 secs
    Loop 3 - 3,19 secs
    Loop 4 - 2,95 secs
    Loop 5 - 3,39 secs
    Trigger enabled
    Loop 1 - 4,83 secs
    Loop 2 - 3,78 secs
    Loop 3 - 4,75 secs
    Loop 4 - 3,91 secs
    Loop 5 - 3,81 secs
    times for 11g:
    Trigger disabled
    Loop 1 - 2,27 secs
    Loop 2 - 2,4 secs
    Loop 3 - 2,3 secs
    Loop 4 - 2,42 secs
    Loop 5 - 2,36 secs
    Trigger enabled
    Loop 1 - 8,01 secs
    Loop 2 - 17,22 secs
    Loop 3 - 29,21 secs
    Loop 4 - 58,43 secs
    Loop 5 - 115,59 secs
    script for create test table
    CREATE TABLE SD3Test
       (MPID INTEGER NOT NULL ENABLE,
    ROWCOUNT NUMBER(10,0),
    CLOSEDROWCOUNT NUMBER(10,0),
    AMOUNT NUMBER(18,2) DEFAULT 0 NOT NULL ENABLE,
    LOCALAMOUNT NUMBER(18,2) DEFAULT 0 NOT NULL ENABLE,
    CLOSED CHAR(1 BYTE) DEFAULT 'N' NOT NULL ENABLE);
    ALTER TABLE SD3Test ADD CONSTRAINT SD3TestPK PRIMARY KEY (MPID);
    --fill test data
    DECLARE mCnt INTEGER;
    BEGIN
    mCnt := 0;
    FOR mCnt IN 1..60000 loop
      INSERT INTO SD3Test (MPID, Amount, LocalAmount, RowCount, ClosedRowCount)
      VALUES(mCnt, 0, 0, 0, 0);
    END loop;
    END;
    --create trigger
    CREATE OR REPLACE TRIGGER SD3TestAU
      BEFORE UPDATE ON SD3Test FOR EACH ROW
    DECLARE
    mInt INTEGER;
    BEGIN
      /*original code of our trigger, but performance problem is
    not depend on it, just depend on existence of this trigger
    IF ((:new.RowCount=:new.ClosedRowCount) and (:new.RowCount>0)) THEN
      :new.Closed:='A';
    ELSE
      :new.Closed:='N';
    end if;
    mInt := 1;
    END;
    / script for run test
    --test for updates with trigger disabled and enabled
    set serveroutput on;
    DECLARE
      mCnt INTEGER;
      mLoop INTEGER;
      mDisEna INTEGER;
      mStart NUMBER;
      mStop NUMBER;
    BEGIN
    --2 loops - first with disabled trigger, second with enabled trigger
    FOR mDisEna IN 1..2 loop
      IF mDisEna = 1 THEN
       execute immediate 'ALTER TRIGGER SD3TestAU disable';
       dbms_output.put_line('Trigger disabled');
      ELSE
       execute immediate 'ALTER TRIGGER SD3TestAU enable';
       dbms_output.put_line('Trigger enabled');
      END IF;
      -- 3 inner loops for measure time
      FOR mLoop IN 1..3 loop
        --update on all records in table
       mStart := dbms_utility.get_time;
       FOR mCnt IN 1..60000 loop
        UPDATE SD3Test
         SET
        ROWCOUNT = ROWCOUNT+1,
        CLOSEDROWCOUNT = CLOSEDROWCOUNT+1,
        AMOUNT = AMOUNT + mCnt,
        LOCALAMOUNT = LOCALAMOUNT + mCnt
        WHERE
         MPID = mCnt;
       END loop;
       mStop := dbms_utility.get_time;
       dbms_output.put_line('Loop ' || mLoop || ' - ' || round((mStop - mStart)/100,2) || ' secs');
      END loop;
    END loop;
    END;
    /

    Hello,
    Your case has been reported as a bug #7173924 (TRIGGER IS MUCH SLOWER IN 11G) few days ago.
    Still on analyze.
    Nicolas.

Maybe you are looking for

  • Help! I have had my iMac G5 fitted with new Logic Board but it doesn't work

    Help! I have had my iMac G5 fitted with new Logic Board but it doesn't work I have just had my iMac G5 First Gen 1.8Ghz fitted with a new Logic Board under the Apple Repair Extension Programme for iMacs. I got the iMac home from the repairers and swi

  • Can't install CF Builder 2

    I am trying to install the latest versin (CF Builder 2, update 2) on my iMac (2013 model, 8GB RAM, OS X 10.8)  The installer launches but the intial screen is blank with only the "next" button visible. It wil not progress from there. I've tried re-bo

  • Service Entry Sheet Multiple Account Assignment--NO QTY AVAILABLE IN PO HIS

    Hi Gurus I have created a service po like following............. Item overview --> Acc *** -K, Item Cat-D, service text, qty=1,opu=AU Item detail------->service tab : service text, qty=10, un=EA ; acc assignment :mul acc assign> distr by qty> 5 in on

  • USB Hard Drive that Disk Utility says it can't unmount

    I have a 93.2 Gb Hard Drive (from an old G4 PowerBook) inside an enclosure with USB connection. While trying to recover data from it using Data Rescue (on a G4 PowerBook), Data Rescue II hung. After restart, the USB Hard Drive can not be read at all.

  • Widescreen in Final Cut Pro

    Hi, I have a question regarding aspect ratio in Final Cut Pro. This is driving me crazy!! I have just converted over to Mac as well as Final Cut Pro.. so far I've been having a great experience. Until now... I've recently completed editing a few vide