After insert & update trigger

I need to write a trigger that if some columns of the master table have changed, the trigger will first insert the change to a copy table. Later on, if there are more changes to the master of the same row, it will compare the new value to the old value and delete the same row in the copy table and insert the latest change. I have wrote the following trigger. Some how when I run it, it has compilation error. Does anyone have any idea on how should I approach this?
create or replace trigger TRITON.AFTER_INSERT_UPDATE_ITM001100after insert or update on TRITON.TTIITM001100for each rowdeclarev_reflag char(1);beginv_reflag:='0';if (:new.T$ITEM != :old.T$ITEM or :new.T$DSCA != :old.T$DSCA) then
delete from ticcrm.ttiitm001100_copy;
insert /*+append*/ into ticcrm.ttiitm001100_copy(T$ITEM, T$DSCA, T$DSCB, T$DSCC, T$DSCD, T$WGHT, T$SEAK, REFLAG)values(:new.T$ITEM, :new.T$DSCA, :new.T$DSCB, :new.T$DSCC, :new.T$DSCD, :new.T$WGHT, :new.T$SEAK, v_reflag);
end if;
end;
/

delete from ticcrm.ttiitm001100_copy;
insert /*+append*/ into ticcrm.ttiitm001100_copy(T$ITEM, T$DSCA, T$DSCB, T$DSCC, T$DSCD, T$WGHT, T$SEAK, REFLAG)values(:new.T$ITEM, :new.T$DSCA, :new.T$DSCB, :new.T$DSCC, :new.T$DSCD, :new.T$WGHT, :new.T$SEAK, v_reflag);
This is simple SQL statements, not PL/SQL.
Use EXECUTE IMMEDIATE for executing it.
P.S. Please do not forget to make good formatting of your code before posting it.

Similar Messages

  • ORA-29532 exception from after insert update trigger

    Trigger code:
    CREATE OR REPLACE TRIGGER SAMS.PERS_ALG_AIU_TRG
         AFTER INSERT OR UPDATE
              ON PERS_ALG
              FOR EACH ROW
    DECLARE
         trans_type          VARCHAR2(1);
         event_id          CONSTANT VARCHAR2(7) := 'A31_ZA1';
         data_src          CONSTANT VARCHAR2(15) := 'SI_A31_ZA1_VW';
         p_row_id          ROWID;
         select_stmt          VARCHAR2(5000);
         XMLString          CLOB;
    BEGIN
         IF INSERTING THEN
              trans_type := 'I';
         ELSE
              trans_type := 'U';
         END IF;
    SELECT ROWID
    INTO p_row_id
    FROM personnel
    WHERE pers_seq = :new.pers_seq;
    select_stmt := 'SELECT * FROM si_a31_ZA1_vw WHERE start_date = MAX(start_date) AND ROW_ID =chartorowid('''||p_row_id||''')';
         -- Produce the XML
    XMLString := si_lib.get_XML(select_stmt);
         -- Insert the transaction
         INSERT INTO si_transaction (transaction_type, event_id, status_id, timestamp, transaction_xml)
              VALUES ( trans_type, event_id, 'CR', SYSDATE, XMLString);
              EXCEPTION
                   WHEN OTHERS THEN
                   RAISE_APPLICATION_ERROR (-20040, sqlerrm);
    END;
    ... is causing ORA-29532 JAVA call terminated by uncaught java exception: java.lang.nullPointerException
    any ideas --- get_XML actually calls dbms_xmlquery.getXML

    When in doubt, break it into pieces and test the pieces. The following is not valid:
    SELECT * FROM si_a31_ZA1_vw WHERE start_date = MAX(start_date)
    Try replacing the above with:
    SELECT * FROM si_a31_ZA1_vw WHERE start_date = (SELECT MAX(start_date) FROM si_a31_ZA1_vw)

  • Bc4j bug at refresh after insert / update

    having a table and a trigger on it that fills an attribute
    in a 9i db. one can take the scott/tiger emp table and use the
    following trigger:
    create or replace trigger t_bri_emp
    before insert on emp
    for each row
    declare
    v_no number(7,2);
    begin
    select user_SEQ.nextval*100
    into v_no
         from dual;
    :new.sal := v_no;
    end;
    then creating a bc4j project with an entity object based on this table (emp)
    and a view object based on the created entity object.
    !!!! when you create the bc4j project you must set the SQL Flavor to SQL92 or OLite
    when you set the attribute settings, for the attribute the trigger is on (sal),
    to refresh after insert / update or both in the entity object you get a
    null pointer when you try to insert a new row and commit.
    java.lang.NullPointerException
         oracle.jdbc.ttc7.TTIoac oracle.jdbc.ttc7.TTCAdapter.newTTCType(oracle.jdbc.dbaccess.DBType)
         oracle.jdbc.ttc7.NonPlsqlTTCColumn[] oracle ....................
    all can be reproduced just useing the wizard and start the bc4j project with the tester
    any workaround ??

    Sven:
    I looked into your issue. It turns out your problem is caused by a bug in the system (bug #2409955).
    The bug is that for non-Oracle SQLBuilder, we are not processing refresh-on-insert and refresh-on-update attributes correctly. We end up forming an invalid SQL statement and the JDBC driver gives the obscure NullPointerException.
    Thus, until 9.0.3, you should not use refresh-on-insert/update attributes on a non-Oracle SQLBuilder.
    If you need the refresh-on-insert/update attribute, here is a possible workaround:
    1. Whenever you invoke the tester, on the first panel, click on the 'Properities' tab. In the list of properties, you should find one for 'jbo.SQLBuilder'. It will say 'SQL92'. Remove it, so that it is empty. Run test tester. Then, the tester will use Oracle SQLBuilder which will handle refresh-on-insert/update attributes correctly for you.
    2. For switching between Oracle SQLBuilder and SQL92 SQLBuilder, you can try the following:
    2a) Locate bc4j.xcfg and your Project??.jpx under your 'src' directory.
    2b) Make copies of these files.
    2c) Edit them so that you have one set for Oracle SQLBuilder and one set for SQL92 SQLBuilder. For Oracle SQLBuilder, make sure these files do NOT have entries like:
    <jbo.SQLBuilder>..</jbo.SQLBuilder> in bc4j.xcfg and
    <Attr Name="_jbo.SQLBuilder" Value="..." /> in Project??.jpx
    When there is no jbo.SQLBuilder entry, BC4J will default to Oracle.
    For SQL92, make sure you have
    <jbo.SQLBuilder>SQL92</jbo.SQLBuilder> in bc4j.xcfg and
    <Attr Name="_jbo.SQLBuilder" Value="SQL92" /> in Project??.jpx.
    Before you run, decide which SQLBuilder to use (for 9.0.2, with retrieve-on-insert/update attrs, you have no choice but to use Oracle SQLBuilder) and copy these files into your class path, e.g.,
    <jdev-install-dir>\jdev\mywork\Workspace1\Project1\classes
    When you get 9.0.3, then you should be able to switch between Oracle and SQL92 SQLBuilders freely.
    Thanks.
    Sung

  • Response.write after insert/update

    Hi
    Could anyone please show me how to do a response.write message on the page after insert/update?
    Wondering especially about the placement and the syntax of the response.
    DWCS5, Access, Asp
    Christian

    I'm sorry to say I don't know how to test values in ASP, have just started to use it.
    I didn't get it to work so I threw away the code and went for an ordinary text response on a second page.
    Might as well get a book and read up on it

  • Create trigger for after insert update

    i have table tt (id number (10), name varchar2(20), status varchar2(1) , stage varchar2(1))
    when i insert data in table tt
    id name status stage
    1 anil a
    then trigger fire and update same value of satge to status
    like
    1 anil a a
    pls give example

    Hi,
    please try this code:
    CREATE OR REPLACE TRIGGER <tiggername>
    AFTER INSERT OR UPDATE
    ON TT
    FOR EACH ROW
    DECLARE
    v_Status varchar2(10);
    BEGIN
    -- Insert record into audit table
    INSERT INTO orders_audit
    ( id,
    name,
    stage)
    VALUES
    ( :new.id,
    :new.name,
    :new.stage);
    select stage into v_status
    from tt where stage = new.stage
    update tt set status = v_status where id = new.id
    END;

  • Insert/Update Trigger error

    Hi all,
    What is wrong with my code?
    SQL> create or replace trigger interval_after_tr
    after insert or update on intervals
    for each row
    begin
    if ((:new.beginning) > (:new.ending)) then
    RAISE_APPLICATION_ERROR(-20061,’BEGINNING VALUE > ENDING VALUE IN THE SAME ROW’);
    elsif ((:new.ending) < (interval_package.pac_ending)) or ((:new.ending) <> (interval_package.pac_beginning))
    RAISE_APPLICATION_ERROR(-20061,’ENDING VALUE IS < ANY ENDING VALUE OR <> ANY OTHER BEGINNING VALUE’);
    elsif ((:new.beginning) > (interval_package.pac_beginning)) or ((:new.beginning) <> (interval_package.pac_ending))
    RAISE_APPLICATION_ERROR(-20061,’BEGINNING VALUE IS > ANY BEGINNING VALUE OR <> ANY OTHER ENDING VALUE’);
    else
    RAISE_APPLICATION_ERROR(-20061,’INSERTED BEGINNING/ENDING VALUE IS INVALID’);
    end if;
    end ;
    Trigger created.
    SQL> show err
    Errors for TRIGGER INTERVAL_AFTER_TR:
    LINE/COL ERROR
    3/42 PLS-00103: Encountered the symbol "?" when expecting one of the
    following:
    ( - + case mod new not null others <an identifier>
    <a double-quoted delimited-identifier> <a bind variable> avg
    count current exists max min prior sql stddev sum variance
    execute forall merge time timestamp interval date
    <a string literal with character set specification>
    <a number> <a single-quoted SQL string> pipe
    <an alternatively-quoted string literal with character set
    specification>
    <an alternatively-q
    Kindly help!
    Regards,
    S.

    Try:
    CREATE OR REPLACE TRIGGER interval_after_tr
    AFTER INSERT OR UPDATE
    ON intervals
    FOR EACH ROW
    BEGIN
    IF ((:NEW.beginning) > (:NEW.ending))
    THEN
    raise_application_error
    (-20061,
    'BEGINNING VALUE > ENDING VALUE IN THE SAME ROW'
    ELSIF ((:NEW.ending) < (interval_package.pac_ending))
    OR ((:NEW.ending) <> (interval_package.pac_beginning))
    THEN
    raise_application_error
    (-20061,
    'ENDING VALUE IS < ANY ENDING VALUE OR <> ANY OTHER BEGINNING VALUE'
    ELSIF ((:NEW.beginning) > (interval_package.pac_beginning))
    OR ((:NEW.beginning) <> (interval_package.pac_ending))
    THEN
    raise_application_error
    (-20061,
    'BEGINNING VALUE IS > ANY BEGINNING VALUE OR <> ANY OTHER ENDING VALUE'
    ELSE
    raise_application_error (-20061,
    'INSERTED BEGINNING/ENDING VALUE IS INVALID'
    END IF;
    END;
    /

  • (Automatic) Refresh of Cached object after insert/update

    Hi,
    (I am using Toplink 9.0.3 against an Oracle Database)
    I am inserting and updating records in the database through objects registered in a TopLink UnitOfWork. I happen to know that certain database columns will get a (changed) values because of Database triggers.
    Is it true that the only way to get these changed values reflected back to the TopLink cache is by explicitly executing a
    session.refreshObject();
    call for every object changed in the UnitOfWork?
    Is there no way to inform TopLink (for example through the descriptors for the relevant classes) that for certain classes after the insert/update an automatic synchronization with the database must be performed?
    I have not been able to find such a setting, but I may have overlooked it - I hope I did.
    Thanks for your help,
    Lucas Jellema (AMIS)

    In this case use a postMerge event -- it will get called after the merge of the cache and then you could update the object explicitly.
    Ultimately, the way to achieve the behavior you're looking for is events or refreshing.
    - Don

  • Refreshing the RowSetBrowser webbean after insert/update(?)

    How do I refresh the RowSetBrowser web bean after inserting or updating and committing a record thru the EditCurrentRecord web bean?
    I am unable to see the new record added in the RowSetBrowser unless I close the browser and re-enter.
    Any advice would be appreciated!
    null

    after you call to iniatialize() in the DWB, you can refresh the cache by calling
    <%
    dbw.getRowset().executeQuery();
    %>

  • "creta user" in an "after insert" table trigger

    Dear members,
    I'm having trouble when I want to create an oracle user in a trigger after inserting in a table.
    It says that I don't have privileges to do so, but my user is DBA, and I can create a new user directly with no problem from this user.
    Do I need a special privilege for some actions through a trigger ?
    Is user creation possible at all in such a trigger ?
    Thanks for your help.

    My guess is that you have the create user privilege granted to you through a role, not directly. Stored procedures don't know about privileges you have through roles.
    Justin
    Distributed Database Consulting, Inc.
    www.ddbcinc.com/askDDBC

  • After/before update trigger

    Hi All
    Does any onoe know
    what 's the difference between after update/insert trigger and before update/insert trigger
    on database tables.

    Hi
    The basic diffrence is
    Before Update triggers before the table is updated and
    After update triggers after the table is updated but
    before the implicit commit fires.
    therefore when you raise the application error a
    implicit Rollback happens and the record is not commited.
    Regards
    Shajesh Nair
    Deloitte.
    [email protected]

  • No database update after insert / update

    Dear all..
    I have created a small report for storing additional invoice text into a z-table. These invoice text could have the lenght of 2560 character and are needed for EDI transmission.
    Directly after saving - I can view them.  After some hours I am always getting empty fields wenn I try to view the data. ... for me it looks like that the table entries are buffered but nor really stored into database. Does a commit work solves this problem ?
    Thanks in advance
    Jürgen

    hi,
    you say :
    Directly after saving - I can view them.
    how? with se16 or program?
    -> try to work with offset
    A.

  • Using Database Change Notification instead of After Insert Trigger

    Hello guys! I have an after insert trigger that calls a procedure, which in turn is doing an update or insert on another table. Due to mutating table errors I declared the trigger and procedure as autonomously transactional. The problem is, that old values of my main tables are inserted into the subtable since the after insert/update trigger is fired before the commit.
    My question is how can I solve that and how could I use the change notification package to call my procedure? I now that this notification is only started after a DML/DDL action has been commited on a table.
    If you could show me how to carry out the following code with a Database Change Notification I'd be delighted. Furthermore I need to know if it suffices to set up this notification only once or for each client seperately?
    Many thanks for your help and expertise!
    Regards,
    Sebastian
    declare
    cnumber number (6);
    begin
    select count(*) into cnumber from (
    select case when (select date_datum
        from
          (select f.date_datum,
            row_number() over (order by f.objectid desc) rn
          from borki.fangzahlen f
          where lng_falle      = :new.lng_falle
          and int_fallennummer = :new.int_fallennummer
          and lng_schaedling   = :new.lng_schaedling
          and date_datum       > '31.03.2010'
        where rn=1) < (select date_datum
        from
          (select f.date_datum,
            row_number() over (order by f.objectid desc) rn
          from borki.fangzahlen f
          where lng_falle      = :new.lng_falle
          and int_fallennummer = :new.int_fallennummer
          and lng_schaedling   = :new.lng_schaedling
          and date_datum       > '31.03.2010'
        where rn=2) then 1 end as action from borki.fangzahlen
            where lng_falle      = :new.lng_falle
            and int_fallennummer = :new.int_fallennummer
            and lng_schaedling   = :new.lng_schaedling
            and date_datum       > '31.03.2010') where action = 1;
    if cnumber != 0 then
    delete from borki.tbl_test where lng_falle = :new.lng_falle
    and int_fallennummer = :new.int_fallennummer
    and lng_schaedling   = :new.lng_schaedling
    and date_datum       > '31.03.2010';
    commit;     
    pr_fangzahlen_tw_sync_sk(:new.lng_falle, :new.int_fallennummer, :new.lng_schaedling);

    It looks like you have an error in line 37 of your code. Once you fix that the problem should be resolved.

  • Update trigger on table fr audit purpose to record column level information

    Hi,
    I want to create a update trigger which will record data in an audit table.
    In audit table I want to have columns like old_value_of_Col and new_value_of_Col.
    This is easily achievable. But my main concern is to add three more columns having the information of:
    1) Which column was updated?
    2) Old value of column that was updated
    3) New value of column that was updated
    If possible, Also if one updates three columns for example, then in such a case. I would like to have three entries in audit table for the corresponding three columns.
    Please help.
    Thanks in advance.

    A few approaches to consider.
    First, if you are on 11g, take a look at Flashback Data Archive: http://download.oracle.com/docs/cd/B28359_01/appdev.111/b28424/adfns_flashback.htm#ADFNS01011
    Second, you can use Fine-Grained Auditing to capture DML statements and bind variables. It is not as easy to reconstruct the before/after picture, but it may be sufficient for some purposes.
    For trigger-based solutions, I have seen the approach you propose (1 row for each column changed) and it is tedious and prone to maintenance headaches. You have to write code for each column, doing compares (remembering to consider NULLs), dealing with different datatypes, etc. We used that design becasue there was an actual requirement to produce a report that needed such a structure.
    An easier trigger-based solution is to create a history table for the table you want to track, with all of the columns from the original, plus whatever else you need for housekeeping. Write an After Insert/Update/Delete trigger on your base table, and populate/insert rows into the history table:
    - For inserts, populate and insert row from the :new. values
    - For deletes, populate and insert a row from the :old. values
    - For updates, popualte and insert a row from the :old. values and another from the :new. values
    I would also have a column to designate whether this is an Insert, Delete, Update-Old or Update-New row.
    Once you have done one example, the rest are easy. If you were sufficiently motivated (I have not yet been :-) ), you could probably write a script to query DBA_TAB_COLS and generate the code.

  • Inserting/updating data in control block based on view

    Hi!
    I`ve created a block based on a view to display data.
    I want this block to be insertable and updateable, that is I will use a on-insert/update trigger to call an insert/update procedure located in the database.
    When trying to change/insert a value in the block, the error message "Error: Can not insert into or update data in a view" pops up. I`ve tried to get rid of this error, without success.
    How can I make a data block based on a view insertable and updateable?
    My guess is that this have something to do with locking the records(there is no rowid in the view)... but I'm not sure.
    Pls advise!!

    Morten
    As well as on-update, on-insert, on-delete triggers you also need an on-lock,
    (even though it might just contain null;) otherwise the form will try to lock the view and fail.
    Actually your terminology is wrong, the block being based on a table or view is not a control block. A control block is not based on anything and has no default functionality for communicating with the database. If it was a control block, the on- triggers would not fire.

  • After update trigger firing on after insert

    Hi All,
    I am using oracle database version 8i.
    I have one database trigger
    create or replace trigger mna_post_update
    after update
    on mobile_number_actions
    for each row
    when (new.mna_status = 'P'
    and new.mna_type in ('I','C','R','D','M','T','A','N','O'))
    begin
    insert into test1234 values (:new.mna_mcp_serial_no,:old.mna_mcp_serial_no);
    end;
    The problem is that it is giving the same value for :new.mna_mcp_serial_no and :old.mna_mcp_serial_no. And also in my table insertion is taken place not updates I have no idea why this trigger is firing on insert?
    Could any one please tell me how is this possible?
    Please help !!

    Are you sure you don't have a similar trigger that is firing on inserts (perhaps you were debugging this code and inadvertently created one that fired on inserts or on inserts & updates)?
    Assuming you are updating MNS_MCP_SERIAL_NO, you should be getting different values in test1234. If you are not, can you post a brief test case (including DDL to create the objects) that shows the problem(s) you're seeing?
    Justin

Maybe you are looking for

  • How to use scroll for tablecontrol in BDC

    Hai Experts,    I have created BDC for IA05 tcode. In that am filling table control. that table control view is 15 lines, but i have to fill 20 entries. for this i am using the below code. In debugging m checking that '=P+' is there in BDCDATA. But w

  • Problems with hard disk, but it won't repair

    Hi, My MacBook Pro has gradually become slow, and it crashes occasionally, especially when multitasking. I verified my hard disk with the Disk Utility, and it told me the following: Verifying volume "Macintosh HD" Checking HFS Plus volume. Checking E

  • Old Hard drive crashed, need to transfer music from iPod to new computer

    Hello. My old hard drive crashed and I bought a new computer. Unfortunately I did not back up any files from my old computer and lost all files including iTunes music. All I have is the music from my iPod. I would like some help or if anyone knows an

  • Using Macbook 2015 with old iMac in target display mode?

    Opinions about the new 12 inch Macbook 2015 aside, I am wondering if I can use my 27 inch iMac mid-2011 in Target Display Mode. I also had trouble finding "daisy chain" solutions to this. Ex. An accessory that will allow me to charge the Macbook whil

  • Why does word startup when Mac is turned on?

    Why does Word startup when computer is turned on? I looked in my startup menu and it is not there.