Trigger AFTER INSERT or UPDATE run twice

Hi people! I have a problem with this trigger, if I insert a record, INSERTING run 2 times still, I guess that the problem is in AFTER INSERTION or UPDATE of THE SAL ON EMP, but I can't find the solution, I m used to read a lot but nothing... Any idea? Thank you and sorry my bad English.

PD: I use oracle database 9i 9.2.0.1.0 enterprise

CREATE OR REPLACE TRIGGER TEMA10EJER1
AFTER INSERTION OR UPDATE OF THE SAL ON EMP
FOR EACH LINE
BEGIN
IF THE INSERTION
UPDATE DEPT
PRESUPUESTO SET = PRESUPUESTO +: new.sal
Where: new.deptno = deptno;
ELSIF UPDATING ('sal') THEN
UPDATE dept
Presupuesto SET = presupuesto -: old.sal +: new.sal
WHERE: new.deptno = deptno;
END IF;
END;

Check your DEPT table, may be there is another trigger that inserting a new record.

Tags: Database

Similar Questions

  • trigger after insert in tables MASTER DETAILS, adding bonuses to employees

    Hi Experts, I am a beginner in PL/SQL and triggers
    =========================
    I have two tables:
    MASTER (DOC_NO, DOC_DATE, BONUS)
    DETAILS (EMP_NO, EMP_NAME, EMP_BONUS)

    I need to distribute the (BONUS) column in table (MASTER) to column (EMP_BONUS) in DETAILS

    by equal parts.

    I need it in (trigger after insert)


    EMP_BONUS: is BONUS count (EMP_NO);.

    example:
    BONUS = 100
    No EMP_NO = 20

    This means (EMP_BONUS = 100/20 = 5).


    I use the 6.0 with 9i DB form
    Help, please

    RARA says:
    Hi Experts, I am a beginner in PL/SQL and triggers
    =========================
    I have two tables:
    MASTER (DOC_NO, DOC_DATE, BONUS)
    DETAILS (EMP_NO, EMP_NAME, EMP_BONUS)

    I need to distribute the (BONUS) column in table (MASTER) to column (EMP_BONUS) in DETAILS

    by equal parts.

    I need it in (trigger after insert)

    EMP_BONUS: is BONUS count (EMP_NO);.

    example:
    BONUS = 100
    No EMP_NO = 20

    This means (EMP_BONUS = 100/20 = 5).

    I use the 6.0 with 9i DB form
    Help, please

    If you want to do after insertion and forms... You can use the trigger to insert after and try something like this

    declare
     a number;
    begin
    select count(emp_no) into a
    from master;
    update details
    set emp_bonus=:bonus/a;
    commit;
    end;
    

    Hope this helps

    If someone useful or appropriate, please mark accordingly.

  • update the column of type char to stem after insert or update the same column

    I have the table "people":

    DESC PEOPLE
    Name Null? Type
    ------------------------------- -------- ------------
    ID NOT NULL NUMBER
    NAME VARCHAR2 (25) NOT NULL

    and I need to make sure that the NAME column is always in uppercase letters, so I did as he illustrated in this link:
    http://asktom.Oracle.com/tkyte/mutate/

    I did this: -.
    ==================================
    CREATE OR REPLACE TRIGGER parent_bi
    BEFORE THE INSERT OR UPDATE
    ON people
    BEGIN
    state_pkg.newrows: = state_pkg.empty;
    END;
    /
    -----------------------------------------------------------------
    CREATE OR REPLACE TRIGGER parent_aifer
    AFTER INSERT OR UPDATE
    ON PEOPLE
    FOR EACH LINE
    BEGIN
    state_pkg.newrows (state_pkg.newrows.COUNT + 1): =: NEW. ROWID;
    END;
    /
    ------------------------------------------------------------------
    CREATE OR REPLACE TRIGGER HR. PARENT_AI
    AFTER INSERT OR UPDATE
    ON HUMAN RESOURCES. PEOPLE
    REFERRING AGAIN AS NINE OLD AND OLD
    FOR EACH LINE
    BEGIN
    BECAUSE me in 1... state_pkg.newrows.count
    LOOP
    UPDATE of the people
    NAME = UPPER (NAME)
    People WHERE. ROWID = state_pkg.newrows (i);
    END LOOP;
    END;
    /
    ======================================

    but nothing is coming, as the same that these triggers do not exist.

    So, what is wrong?
    and how I workaround to make this statement:-
    Setting a DAY people SET NAME = UPPER (NAME);
    whenever I update or insert in the name column.

    It is much simpler that that - you just need a BEFORE INSERT trigger

    CREATE OR REPLACE TRIGGER your_trigger_name
      BEFORE INSERT OR UPDATE ON persons
      FOR EACH ROW
    BEGIN
      :new.name := UPPER( :new.name);
    END;
    /
    

    As you can see from this example, which will force all uppercase

    SQL> create table persons (
      2    name varchar2(10)
      3  );
    
    Table created.
    
    SQL> CREATE OR REPLACE TRIGGER your_trigger_name
      2    BEFORE INSERT OR UPDATE ON persons
      3    FOR EACH ROW
      4  BEGIN
      5    :new.name := UPPER( :new.name);
      6  END;
      7  /
    
    Trigger created.
    
    SQL> insert into persons values( 'justin' );
    
    1 row created.
    
    SQL> insert into persons select lower(ename) from emp;
    
    14 rows created.
    
    SQL> select * from persons;
    
    NAME
    ----------
    JUSTIN
    SMITH
    ALLEN
    WARD
    JONES
    MARTIN
    BLAKE
    CLARK
    SCOTT
    KING
    TURNER
    ADAMS
    JAMES
    FORD
    MILLER
    
    15 rows selected.
    

    Also, you generally want to add a check constraint to ensure that NAME = UPPER (NAME).

    Justin

  • Trigger after insert

    After an insertion in table 1, I want to take the value of the transaction and use it in a custom to insert trigger in an another datbase 2 values. One is the primary key of the table 1 transaction value and the other is a variable of the connected user's session. I can get the value of the user of the session, but I can't get the value of the transaction field.

    $updateRequestDate = "INSERT INTO request_notify (id_request, username) Values ({rsrequest.id_request}," ".). $_SESSION ["kt_login_user"]. "')";
    $update_result = $tNG-> connection-> execute ($updateRequestDate);
    {if(!$update_result)}
    $updateError = new tNG_error ("' error affecting the logged in State to N ', array(), Array();")
    Return $updateError;
    } else {}
    return null;
    }

    I have the custom trigger after insert transaction.

    How do you get the value of a transaction for a custom trigger field?

    Please try with the help of the

    $tNG-> getColumnValue ("column_name")

    method instead.

    See you soon,.

    Günter

  • Create the trigger after insert

    Hello

    I would like to ask how to create a trigger after insert on a table. Basically, what I wanted to do are when an insert to table1 it will insert the records to table2. But the problem is that folders that will be inserted in the new tables are entries/fields, who lived in NEW York City (on table of ld)

    after insertion, I wanted to add another field in table2 as status


    create table table1)

    Name varchar2 (55),
    City varchar2 (55)

    );

    create (table2)

    Name varchar2 (55)
    status int (1)
    )

    Hope you could help me.

    Thank you

    Best regards

    antok1015 wrote:
    Hello

    I would like to ask how to create a trigger after insert on a table. Basically, what I wanted to do are when an insert to table1 it will insert the records to table2.

    It's easy...

    SQL> create table table1(
      2    Name varchar2(55),
      3    City varchar2(55)
      4  );
    
    Table created.
    
    SQL>
    SQL> create table table2 (
      2    Name varchar2(55),
      3    status number(1)
      4  );
    
    Table created.
    
    SQL>
    SQL> create or replace trigger trg_tbl1 after insert on table1
      2  for each row
      3  begin
      4    insert into table2 values (:new.name, 1);
      5  end;
      6  /
    
    Trigger created.
    
    SQL> insert into table1 values ('Fred','Bob');
    
    1 row created.
    
    SQL> select * from table2;
    
    NAME                                                        STATUS
    ------------------------------------------------------- ----------
    Fred                                                             1
    
    SQL>
    

    But the problem is that folders that will be inserted in the new tables are entries/fields, who lived in NEW York City (on table of ld)

    after insertion, I wanted to add another field in table2 as status

    This is not sensible. Please explain what you mean.

  • TRIGGER BEFORE INSERT OR UPDATE OR DELETE

    I want to create a single trigger before each insert or update or delete, a record gets copied into the AUDIT table. works very well on the insertion and to day but you have problem clear.

    Can you please help me debug this error. The problem of mutation.

    create or replace

    BIU_FS_Test_T RELAXATION

    BEFORE INSERT OR UPDATE OR DELETE

    ON FS_Test

    REFERRING AGAIN AS NINE OLD AND OLD

    FOR EACH LINE

    DECLARE

    number of voffender_history_id;

    Start

    IF the INSERTION

    SELECT FS_Test_history_seq. nextval in the double voffender_history_id;

    INSERT INTO FS_Test_history (OFFENDER_HISTORY_ID,

    OFFENDER_ID, FIRST_NAME, MIDDLE_NAME, LAST_NAME.

    SX, SKIN_TONE, HEIGHT, WEIGHT, RACE, EYE_COLOR,

    HAIR_COLOR, BLOOD_TYPE, VARIOUS, DATE_OF_BIRTH.

    PLACE_OF_BIRTH, TRANSACTION)

    VALUES (voffender_history_id,

    : new. OFFENDER_ID,: new. First name: new. MIDDLE_NAME,: new. LAST_NAME,

    : new. RACE: new. SX,: new. SKIN_TONE,: new. HEIGHT: new. WEIGHT: new. EYE_COLOR,

    : new. HAIR_COLOR,: new. BLOOD_TYPE,: new. VARIOUS: new. DATE_OF_BIRTH,

    :new. PLACE_OF_BIRTH,

    "INSERT");

    ELSIF UPDATE

    et (

    NVL (:OLD. First name, 'x') <> nvl():NEW. First name, 'x') or

    NVL (:OLD. MIDDLE_NAME, 'x') <> nvl():NEW. MIDDLE_NAME, 'x') or

    NVL (:OLD. Last_name, 'x') <> nvl():NEW. Last_name, 'x') or

    NVL (:OLD. RACE 0) <> nvl():NEW. RACE 0) or

    NVL (:OLD. SX 0) nvl(:NEW <>.) SX 0) or

    NVL (:OLD. SKIN_TONE 0) <> nvl():NEW. SKIN_TONE 0) or

    NVL (:OLD. HEIGHT 0) <> nvl():NEW. HEIGHT 0) or

    NVL (:OLD. WEIGHT 0) <> nvl():NEW. WEIGHT 0) or

    NVL (:OLD. EYE_COLOR 0) <> nvl():NEW. EYE_COLOR 0) or

    NVL (:OLD. HAIR_COLOR 0) <> nvl():NEW. HAIR_COLOR 0) or

    NVL (:OLD. BLOOD_TYPE 0) <> nvl():NEW. BLOOD_TYPE 0) or

    NVL (:OLD. VARIOUS, ' x') <> nvl():NEW. VARIOUS, ' x') or

    NVL (:OLD. DATE_OF_BIRTH, January 1, 1900 ") <> nvl():NEW. " DATE_OF_BIRTH, January 1, 1900 ") or"

    NVL (:OLD. PLACE_OF_BIRTH 0) <> nvl():NEW. PLACE_OF_BIRTH 0)

    )

    THEN

    SELECT FS_Test_history_seq. nextval in the double voffender_history_id;

    INSERT INTO FS_Test_history (OFFENDER_HISTORY_ID,

    OFFENDER_ID, FIRST_NAME, MIDDLE_NAME, LAST_NAME.

    SX, SKIN_TONE, HEIGHT, WEIGHT, RACE, EYE_COLOR,

    HAIR_COLOR, BLOOD_TYPE, VARIOUS, DATE_OF_BIRTH.

    PLACE_OF_BIRTH, TRANSACTION)

    VALUES (voffender_history_id,

    : new. OFFENDER_ID,: new. First name: new. MIDDLE_NAME,: new. LAST_NAME,

    : new. RACE: new. SX,: new. SKIN_TONE,: new. HEIGHT: new. WEIGHT: new. EYE_COLOR,

    : new. HAIR_COLOR,: new. BLOOD_TYPE,: new. VARIOUS: new. DATE_OF_BIRTH,

    :new. PLACE_OF_BIRTH, "UPDATE");

    ELSIF DELETION THEN

    SELECT FS_Test_history_seq. nextval in the double voffender_history_id;

    SELECT FS_Test_history_seq. nextval in the double voffender_history_id;

    INSERT INTO FS_Test_history (OFFENDER_HISTORY_ID,

    OFFENDER_ID, FIRST_NAME, MIDDLE_NAME, LAST_NAME.

    SX, SKIN_TONE, HEIGHT, WEIGHT, RACE, EYE_COLOR,

    HAIR_COLOR, BLOOD_TYPE, VARIOUS, DATE_OF_BIRTH.

    PLACE_OF_BIRTH, TRANSACTION)

    VALUES (voffender_history_id,

    : new. OFFENDER_ID,: new. First name: new. MIDDLE_NAME,: new. LAST_NAME,

    : new. RACE: new. SX,: new. SKIN_TONE,: new. HEIGHT: new. WEIGHT: new. EYE_COLOR,

    : new. HAIR_COLOR,: new. BLOOD_TYPE,: new. VARIOUS: new. DATE_OF_BIRTH,

    :new. PLACE_OF_BIRTH, 'CLEAR');

    END IF;

    end;

    Error I get

    Error from the 1 in the command line:

    Remove from the fs_test where PK = 41476

    Error report:

    SQL error: ORA-04091: table get OUT. SOR_O_HISTORY is changing, function of triggering/can not see

    ORA-06512: at «GET. » BIU_FS_TEST_T', line 111

    ORA-04088: error during execution of trigger ' EB. BIU_FS_TEST_T'

    04091 00000 - «table %s. » "%s is changing, function of triggering/can not see.

    * Cause: A trigger (or plsql user-defined function that is referenced in)

    ( this statement) attempted to watch (or modify) a table that has been

    in the middle to be modified by the statement that shot.

    * Action: Rewrite the trigger (or function) so it does not read this table.

    PS 11g r2

    Thank you.

    n_shah18-

    Is there a parent-child relationship between the tables involved in the triggering event? Is there a foreign key used above the child table that references the parent table?

    If you have a parent-child relationship and a trigger on the parent table must be running some DML on the child table, and, if the child table as a foreign key (FK) back to the parent table, any DML on the child table will cause a recursive SQL statement to check the constraint. Indirectly, this will cause an exception table mutation.

    So watch the dependencies on SOR_O_HISTORY / FS_TEST_HISTORY/all other related table. A FOREIGN KEY can make it to mutate (no pun intended).

    Hope this will help you find the root cause.

  • Problem with trigger AFTER INSERT

    Hi all

    I am updating a column in the table by adding 2 characters 'a_' after INSERTION using the trigger.

    Now when I insert data in the table a trigger is fired for INSERTION.
    According to the syntax, I think that we cannot pass parameters in a trigger.
    I have a test10 table that looks like this.
    t1    varchar2(10)
    t2    varchar2(10)
    t3    varchar2(10)
    t4    number
    t5    number
    
    t1 is kinda primary_key and t2 is unique though the table isn't structured like that but the data in it follows that.
    The code in the trigger looks like this 
    
    CREATE OR REPLACE TRIGGER test10_t1 
      AFTER INSERT 
      ON test10 
      FOR EACH ROW
    BEGIN
      IF INSERTING THEN
        UPDATE test10 SET t1 = 'a_'||:old_value WHERE t1 = ?;  -- I need to mention the parameter here but not sure if we can pass param in a trigger 
      END IF;
    END;
    If I omit the WHERE clause, all records are updated. Is there another way to solve the problem?

    THX
    Rod.

    There is no need to use a clause of update.

    Have you tested the relaxation that I suggested in my last post?

  • Creating a trigger to insert delete update with the sequence number

    Hey all,.
    I have two tables. tbl_main, tbl_temp. Whenever a record is inserted, deleted, updated in tbl_main, I need to insert the records in tbl_temp. All field/column names are exactly the same, except that in tbl_temp, I now have a single column by using a sequence number, a column to determine if the record has been updated, remove, modified(hence the codes) and the date when a record has been added to the table.
    So far, that's what I have:

    create or replace
    audit_trg relaxation
    after update or insert or delete ON tbl_main
    for each line
    Start
    If the update can
    insert into tbl_temp (seq_id, idx, ctl, action_taken, date_added)
    VALUES
    (temp_seq.nextval, idx, mke, ctl, sysdate, 'U');
    ELSif INSERTION then
    insert into tbl_temp (seq_id, idx, ctl, action_taken, date_added)
    VALUES (temp_seq.nextval, idx, mke, ctl, 'n', sysdate);
    ELSIF deletion then
    insert into tbl_temp (seq_id, idx, ctl, action_taken, date_added)
    VALUES (temp_seq.nextval, idx, mke, ctl, would be ', sysdate);
    END IF;
    END audit_trg;

    I tried several combinations, but I get many compilation errors. This code looks good or I am the way of track? Thanks in advance.

    Who looks fine for me. What are the mistakes are you?

    Assuming that MKE and CTL are columns in the base table, your INSERT statements will insert either the: new.mke and: new.ctl values or the: old.mke and: old.ctl values in the table. Presumably, you could insert the: new values for inserts and updates, and the: old values for deletions.

    Justin

    Published by: Justin Cave 27 February 2009 16:08

    DOH! Just noticed the error...

  • BSOD on all options after starting windows updates running.

    I ran the windows updates last night I shut down my computer.  I remember it being about 12 updates to run.

    Windows Vista, 32-bit

    This morning, I rebooted my computer and during the loading sequence, updates continue (the non-graphical part) and then I got a BSOD.  I tried to run all the security modes and got the same message.

    I ran repair my system disk and got the message that he could not repair the version of windows.  I tried a system restore, but it said I had no save points.

    Is there a way to manually tell it that updates have been an uninstall from the reapir vista disk command prompt?

    The specific the BSOD error code is
    0x0000007E (0xC0000005, 0x8264CB56, 0x803998CC, 0x803995C8)

    Any help which is not one of these answers canned that has a bunch of stuff I can't do since I can't on something else that the ERD would be useful.
    Thank you!

    In the end I solved it me - so if someone runs into similar codes - here is the summary:

    I ran Windows Update.
    On reboot the part of the update that runs in non-graphical mode full - then crashed by the computer.
    I got BSOD screens whenever I tried to boot in any mode.
    The specific error code is 0x0000007E (0xC0000005, 0x8264CB56, 0x803998CC, 0x803995C8)
    I tried the repair disk installation process - which could not find anything.
    I couldn't do a system restore point, because they were all gone.
    I called Microsoft - they were very nice, but their only solution was to re - install which was not possible for me.
    I downloaded and created a boot cd on another computer that could run antivirus software.
    The disc has been call BootCD Secured2k - there is a forum on the Mcafee site about this.
    I used it and found a Patched - atapi.sys trojan that he removed from the case.
    (Reading between the lines - this thing has been disrupted by the Microsoft Update that caused the mess)
    Then I got a new problem starting with the error code: 0x0000007b 0x80399bb0
    Same problem of being unable to boot in any mode.
    Same problem of being useless installation disc repair.
    After leaving it for a few hours, it occurred to me that perhaps when atapi.sys, that Trojan has been deleted the file was so.
    I connected the command line available from the installation disc advanced repair options.
    ATAPI.sys had indeed disappeared.
    I used the X:\windows\system32\drivers\atapi.sys and copied on my C:\Windows\system32\drivers.
    And presto! -my windows starts with happiness and everything seemed to work.
    (Why can't notice of repair of microsoft one missing disk or messed up file atapi.sys?)

    Unfortunately a few days later I noticed the Windows updates not working and I couldn't go even this part of the site.
    I tried everything I could think of and failed.
    So I called Mircorosoft again.
    We spent an hour on the phone and they found the problem this time!
    I used OpenDNS as my DNS provider for performance of problems caused by Time Warner.
    For some reason any OpenDNS blocking any attempt on my end to reach the Microsoft Update sites.
    I went from Microsoft recommended DNS and my computer was happy again.
    Everything has been happy since.

    And just to prove that I learned my lesson - I bought Norton Ghost and tries to configure full backups regular since the system restore point says that it don't work for me (I have a vista upgrade a XP Home machine on a FAT file system)

    So:
    Secured2K bootable anti-virus CD (and you can run other analyses of viruses such as PA recommended wear)
    If ATAPI. SYS is removed or bad - I copied it from the disc command prompt install.
    If you Microsoft updates stop working and you can't reach their windowsupdate.microsoft.com - check your DNS.

  • Anyway to get a procedure to be executed after the INSERT or update?

    11g

    Hello

    I get an ORA-04091 error when I try to get a trigger to fire a procedure for me.

    Is it possible to get a procedure to run after all the INSERTIONS and UPDATES are completed.

    I tried to use a trigger "AFTER INSERT or UPDATE", but it hits the error ORA-04091.

    Ben

    And there is your problem

    insert_recheck_record_prc

    This procedure (set on the #184 line) is called in the TEST_AIUDR (line #216) trigger located on the ASSESSMENT.

    But the procedure QUESTIONS this evaluation online #191 table

    INSERT

    IN HARVEST_PLANNER (CLIENT_PRIORITY)

    SELECT b.CLIENT_PRIORITY

    OF HARVEST_PLANNER b

    EVALUATION a

    That causes the exception table mutation. The ASSESSMENT table is the mutation when the trigger on the #191 line. You cannot query the table in the procedure.

  • trigger for insertion of a table to another table

    Hello again,

    I tried to write a trigger after insert or update will happen in table 1, it will move some values in another table, as shown below:

    Create or replace trigger Insert_Amount_Credit after insert or update on Reciept_Voucher

    Referencing NEW AS NEW OLD OLD FOR EACH LINE AS
    Start

    Insert into customer_Details (Transaction_Date, client_name, Description, credit) values (new. Rec_Date, new. Client_name, CONCAT (' receipt number:', again.) Rec_ID), new. Amount);

    End;

    /

    The trigger was created but with compilation error... and my question is:

    1. How do I write the code above in the best way?

    2. How can I enough the other table with a table concatenated as what I was trying to make above?

    any idea?

    Something like that?

    CREATE OR REPLACE TRIGGER trig_ins_testtrg2

    BEFORE INSERT OR UPDATE ON test_trg1

    FOR EACH LINE

    BEGIN

    INSERT INTO test_trg2 (curr_date,

    job_id,

    reason,

    credit)

    VALUES (SYSDATE,

    : NEW.id,.

    : NEW.receipt_no |:NEW.description,.

    (: NEW.amount);

    END;

  • Insert or update trigger by passing the value to the stored procedure

    My task is to write a trigger that will pass a value for an insert or update to a stored procedure.

    It's Friday and I am not clear thinking, forgive me...


    Create or replace trigger < name of the trigger >

    After you insert or update table XXX
    for each line


    Run the Just_Do_It procedure
    (userid = new.user_id).


    If the table XXX has the userid column, and I want the trigger to get it and send it to Just_Do_It.
    what Miss me?

    Thank you.
    CREATE OR REPLACE TRIGGER trigger_name
      AFTER INSERT OR UPDATE ON table_name
      FOR EACH ROW
    BEGIN
      just_do_it( :new.user_id );
    END;
    

    Justin

  • You want to capture update dates, with trigger on a view to refresh quickly materialized. But trigger on MV consider inserting and updates are inserts only.

    Oracle Database 11 g Enterprise Edition Release 11.2.0.4.0 - 64 bit Production

    PL/SQL Release 11.2.0.4.0 - Production

    CORE Production 11.2.0.4.0

    AMT for Linux: Version 11.2.0.4.0 - Production

    NLSRTL Version 11.2.0.4.0 - Production

    I create the structure of the table like that.

    create table test1 (a primary key, b (2) char number, date c, d varchar2 (10), date of e);

    create table test2 (number of ab, cd (2) tank, date of the ef, gh varchar2 (10), date of the ij, kl varchar2 (100));

    Create materialized view log on test1;

    create materialized view fast refresh test1_v on commit in select * from test1;

    I have create a trigger of the sample

    CREATE OR REPLACE TRIGGER test1_trig

    AFTER INSERT OR UPDATE OR DELETE

    ON test1_v

    FOR EACH LINE

    DECLARE

    lr_test2 test2% ROWTYPE;

    lv_error VARCHAR2 (4000);

    BEGIN

    lr_test2. AB: =: NEW.a;

    lr_test2. CD: =: NEW.b;

    lr_test2. GH: =: NEW.d;

    IF THE INSERTION

    THEN

    lr_test2. EF: = SYSDATE;

    lr_test2.IJ: = SYSDATE;

    lr_test2.KL: = 'INSERT ';

    INSERT INTO test2

    VALUES lr_test2;

    ELSIF UPDATE

    THEN

    lr_test2.IJ: = SYSDATE;

    lr_test2.KL: = 'UPDATE ';

    UPDATE test2 = lr_test2 ab WHERE = LINE: OLD.a;

    ELSIF REMOVAL

    THEN

    DELETE FROM test2

    AB = WHERE: old.a;

    END IF;

    EXCEPTION

    WHILE OTHERS

    THEN

    lv_error: = SQLERRM;

    INSERT INTO XXDOMINO_FG_DATA_LOAD_ERROR

    VALUES ('test1_trig',

    : OLD.a,.

    "test1_trig,"

    LV_ERROR,

    SYSDATE);

    COMMIT;

    END test1_trig;

    /

    So, if check you my code,.

    When I insert EF = SYSDATE, IJ = SYSDATE.

    Update EF is not changed, IJ = SYSDATE.

    So I like to capture their insertion and update dates.

    But if updates or insert arrives on the materialized table. The trigger themselves as an INSERT only.

    So how do you capture the updates?

    I use the statemnet with out merger with performance and also able to capture the update dates.

    CREATE OR REPLACE TRIGGER test1_trig_merge

    AFTER INSERT OR UPDATE OR DELETE

    ON test1_v

    FOR EACH LINE

    DECLARE

    lr_test2 test2% ROWTYPE;

    lv_error VARCHAR2 (4000);

    BEGIN

    IF THE REMOVAL

    THEN

    DELETE FROM test2

        AB = WHERE: old.a;

    ELSIF INSERTION

    THEN

    MERGE INTO test2 one

    B using (SELECT 1 FROM DUAL)

    WE (ab =: new.a)

    WHEN MATCHED

    THEN

    UPDATE the VALUE ab =: NEW.a.

    CD =: NEW.b,

    GH =: NEW.c

    IJ = SYSDATE,

    KL = "Update"

    AB WHERE =: old.a

    WHEN NOT MATCHED

    THEN

    INSERTING VALUES (: NEW.a,)

    : NEW.b,.

    : NEW.c.

    : NEW.d,.

    : NEW.e,.

    "INSERT");

    END IF;

    EXCEPTION

    WHILE OTHERS

    THEN

    lv_error: = SQLERRM;

    INSERT INTO XXDOMINO_FG_DATA_LOAD_ERROR

    VALUES ('test1_trig',

    : OLD.a,.

    "test1_trig,"

    LV_ERROR,

    SYSDATE);

    END test1_trig_merge;

    /

    DISPLAY ERRORS;

  • Help me in creating a trigger Insert and Update Options

    Hello

    Please help me in creating a trigger.

    My requirement is that, after insert or update on a Table, I want to launch an event.

    I have started this way, but does not know how to fully implement it.

    I have a dept table


    CREATE TRIGGER DepartmentTrigger
    INSERT AFTER on Dept
    BEGIN
    INSERT INTO mytable VALUES("123","Kiran");
    END DepartmentTrigger;


    Please tell me how I can put the update option also.

    Thanks in advance.

    Please tell me how I can put the update option also.

    Add "or update". ;-)

    Here are a few suggestions, but you definitely need to refer to the manual page that suggested the previous poster.

    CREATE OR REPLACE the TRIGGER DepartmentTrigger
    AFTER INSERT or Update ON Dept
    BEGIN
    INSERT INTO mytable VALUES(:new.) Dept 'DEPT ADDED OR CHANGED');
    END DepartmentTrigger;

    The "or replace" means that you can replace the shutter button as you develop without having to type in a drop statement each time. Just change and reissue your script over and over again until you get it right.

    The addition of "update or" or "Or remove" fact the trigger too much fire for these events. Note, you peut want separate triggers in different scripts and with different names for each event. You must decide whether your design is really the same thing either an insert or an update.

    : new. Dept, this is how you should refer to the vale has changed the Dept column (: old.) Dept is the previous value). I changed the double quotes in the string in the clause VALUES of apostrophes.

    Andy

  • trigger after import table

    Hi all
     CREATE TABLE  "T_EGREE" 
       (     "LIDER" NUMBER(5,0), 
            "TYPE NUMBER(1,0)
     CONSTRAINT "T_EGREE_PK" PRIMARY KEY ("LIDER", "TYPE") ENABLE)
    CREATE OR REPLACE TRIGGER  "AI_T_EGREE" 
    after insert or update on T_EGREE
    for each row
    begin
    if inserting then
    insert into t_sum  (lider,type,AMOUNT)
    values (:NEW.lider,:NEW.type,0);
    end if;
    if updating then
    insert into t_sum (lider,TYPE,AMOUNT)
    values (:NEW.lider,:NEW.type,0);
    end if;
    exception
    when others then
    RAISE_APPLICATION_ERROR (-20505,'insert/update on t_egree failed ,
    due to unique constraint on table t_sum');
    END;
    
    suppose that t_egree contains 34 rows .
    -------------------------------------------------------------
    CREATE TABLE  "T_SUM" 
       (     "LIDER" NUMBER(5,0), 
         "TYPE" NUMBER(1,0),
            "AMOUNT"  NUMBER(3), 
         CONSTRAINT "T_SUM_PK" PRIMARY KEY ("LIDER", "TYPE") ENABLE)
    I have a scenario that t_sum of the table will be empty and t_egree table will be created by importing the file.
    in this case, after you import the table of t_egree, the t_sum table will be blank.
    is there a solution to overcome this problem?
    Thanks in advance
    Naama

    Don't do the following:

    when others then
    RAISE_APPLICATION_ERROR (-20505,'insert/update on t_egree failed ,
    due to unique constraint on table t_sum');
    

    You are hiding the real error, which are not necessarily always an ORA-00001...
    Get rid of these three lines in your code.

Maybe you are looking for

  • Satellite L650 - 1 M 0: standard keyboard by default for the backlit keyboard replacement

    Hello Can a laptop Toshiba L650 - 1 M 0 can replace the standard keyboard by default for the backlit keyboard? Sorry for my bad English, but I used the Google Translator because I do not know how the English language. I only know the Polish ;) Please

  • USB drive not detected on RN Ultra2 +.

  • Buy and download movies on Razr Maxx HD?

    Hello. I just got the Razr Maxx HD and is very satisfied. My previous phone was a HTC and with which I could buy and download movies from HTC Watch. In this way, I could see the movie offline whenever I had fun. My question is; Motorola has something

  • T500 swtichable fuzzy on external monitor

    Hello I have a T500 and graphics switchable, updating all the drivers. I'm using a samsung syncmaster 931b monitor attached to a lenovo docking station. When I use graphics performance, it works fine. When I pass the energy-saving intel, everything b

  • XP does not start on the first try to start

    I just reinstalled XP Pro SP3 on new 250 GB HD HD partitioned C - equal D. DΘmarrage initialization stops and I have to hit reset in order to get Windows to load. Any ideas on what I should do to correct so machine will start on the first try.