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...

Tags: Database

Similar Questions

  • Updated with the sequence column

    Hello

    Using oracle 10g on Windows XP

    I have a table that is having a lot of lines (75,000). I want to update the (recno) column with a sequence number of 1 to the order of 75,000 by MyColumn.

    I got below the response of:
    Re: Insert the sequence number in a table
    CREATE SEQUENCE SAMPLE_SEQ ALL CACHE 20 NOMAXVALUE MINVALUE NOCYCLE 1 INCREMENT OF 1 START WITH 1.

    But how do I get the first order column mycolumn. I mean that I want to give the sequence number; but in the order of MyColumn. It is our application need to have a column in a sequence.

    Thanks in advance.
    Concerning

    try something like:

    merge into mytable a
    using
    (select rid, rownum rnum from (
     select rowid rid
     from mytable
     order by mycolumn) b
    on (a.rowid = b.rid)
    when matched then update
       set a.recno = b.rnum
    
  • ODI 12 c: IKM for differential insert and update with a sequence in the target table

    Hello

    I have a map where I fill in a column of my target table using a database sequence. Now my mapping is supposed to load the target gradually table. So I need a revenge for update and incremental insert. Now with this differential IKM it compares all the columns to match all colmuns line to understand, it should be an insert or update. Now, the following code shows that when the ROW_WID is loaded with a sequence of database.

    If NOT EXISTS

    (select 1 from W_LOV_D T

    where T.ROW_WID = S.ROW_WID

    and ((T.CREATED_BY = S.CREATED_BY) or (T.CREATED_BY IS NULL and S.CREATED_BY IS NULL)) and

    ....

    ....

    < the rest of the comparison of columns >

    )

    So when running ODI returns following error

    Caused by: java.sql.SQLSyntaxErrorException: ORA-00904: "S". "" ROW_WID ": invalid identifier

    Please suggest if there is no other IKM I should use or if there is another way around it without changing the code IKM...

    Hi Marc,

    Thanks for your reply.

    I had solved it. The incremental update process inserts all rows from the source table to I$ table that exists in the target table. It does so by the where sql such as mentioned in my questions as

    WHERE THERE is NOT ( . COLUMNS = . COLUMNS)

    Now in the incremental update IKM Oracle to retrieve all the columns it uses the substitution with parameter as TABLE TARGET. Due to this column sequence will in the comparison and the request fails. When I used the IKM SQL incremental update it used INTEGRATION TABLE as parameter table to pick up the columns, as I'd mentioned in the target sequence is run, so it does not get the sequence column.

    Simple answer: to solve this, use incremental update of the SQL IKM.

    Thank you

    SM

  • 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.

  • Create id, id of the update with the date for each record

    Hello

    Please give me brief idea or document for this concept:

    I need to create id, date, update id, updated for each record inserted or updated in the database (multiple tables).

    (1) how the user id can be obtained?
    (2) is it better if I use views instead of tables for this?
    (3) is it possible for each record?

    Please show me the full scenario. a piece of code can also be useful.

    Thanks in advance.

    http://psoug.org/reference/table_trigger.html

    Concerning
    Biju

  • Insert/update of the XML help merge and to generate the sequence number

    Hello

    I'm working on Oracle 11 g.

    I have a doubt with loading XML.
    I get an xml and I need to insert or update data in a table. What I can accomplish by using the MERGE statement.
    But there is a column in A table, I need to fill with a sequence number, based on the data sent in the xml file.
    The XML does not send the data in this column.
    And I have to make sure that sequence is created according to the order in which the records are present in xml.
    For example the MERGER is insert five rows and update two lines and insert again 3 rows of xml in table A. The sequence number must be created in the same order for the column in the table.
    Also for every new XML, the sequence starts with 1 and ends with the number of records in the xml file. I can't create a sequence and use the seq.nextval.

    Please let me know, there is a way to achieve this.

    Thank you!

    Published by: 934451 on 8 August 2012 06:33

    Published by: 934451 on 8 August 2012 06:50

    Hello

    As a result of your previous thread: {: identifier of the thread = 2403469}

    You can use the clause for ORDINALITE in XMLTable to generate the necessary sequence:

    MERGE INTO target_table t
    USING (
      SELECT x.seq_num, x.pk_id, x.col1, x.col2, ...
      FROM XMLTable(
             '/root/record'
             passing my_xml_doc
             columns seq_num FOR ORDINALITY
                   , pk_id   number       path 'ID'
                   , col1    varchar2(30) path 'COL1'
                   , col2    varchar2(30) path 'COL2'
                   , ...
           ) x
    ) src
    ON ( t.pk_id = src.pk_id )
    WHEN MATCHED THEN UPDATE
     SET t.seq_num = src.seq_num
       , t.col1 = src.col1
       , t.col2 = src.col2
       , ...
    WHEN NOT MATCHED THEN INSERT
     (seq_num, pk_id, col1, col2, ...)
     VALUES (src.seq_num, src.pk_id, src.col1, src.col2, ...)
    ;
    
  • How to modify and update a line later was inserted and updated in the doDML() method?

    Mr President

    Jdev worm is 12.2.1

    How to modify and update a line later was inserted and updated in the doDML() method?

    I added two rows in my table a method of action-listener in bean managed and secondly with operation doDML() as below.

    Method 1-first row in managed bean

        public void addNewPurchaseVoucher(ActionEvent actionEvent) {
            // Add event code here...
            BindingContainer bindings = BindingContext.getCurrent().getCurrentBindingsEntry();        
            DCIteratorBinding dciter = (DCIteratorBinding) bindings.get("VoucherView1Iterator");        
            RowSetIterator rsi = dciter.getRowSetIterator();        
            Row lastRow = rsi.last();        
            int lastRowIndex = rsi.getRangeIndexOf(lastRow);        
            Row newRow = rsi.createRow();        
            newRow.setNewRowState(Row.STATUS_NEW);        
            rsi.insertRowAtRangeIndex(lastRowIndex +1, newRow);         
            rsi.setCurrentRow(newRow);
            
            BindingContainer bindings1 = BindingContext.getCurrent().getCurrentBindingsEntry();        
            DCIteratorBinding dciter1 = (DCIteratorBinding) bindings1.get("VdetView1Iterator");        
            RowSetIterator rsi1 = dciter1.getRowSetIterator();        
            Row lastRow1 = rsi1.last();        
            int lastRowIndex1 = rsi1.getRangeIndexOf(lastRow1);        
            Row newRow1 = rsi1.createRow();        
            newRow1.setNewRowState(Row.STATUS_NEW);        
            rsi1.insertRowAtRangeIndex(lastRowIndex1 +1, newRow1);         
            rsi1.setCurrentRow(newRow1); 
            
            
        }
    


    Method of doDML() of line 2 seconds in the entityImpl class


        protected void doDML(int operation, TransactionEvent e) {        
            setAmount(getPurqty().multiply(getUnitpurprice()));
           
            if (operation == DML_INSERT)  
                       {          
                         insertSecondRowInDatabase(getVid(),getLineitem(),getDebitst(),
        (getPurqty().multiply(getUnitpurprice()).multiply(getStaxrate())).divide(100));  
                           }
                           
                           if(operation == DML_UPDATE)
                           {
                               
                           updateSecondRowInDatabase(getVid(),getLineitem(),getDebitst(),
        (getPurqty().multiply(getUnitpurprice()).multiply(getStaxrate())).divide(100));                        
                           }                                       
            super.doDML(operation, e);
        }
    
        private void insertSecondRowInDatabase(Object value1, Object value2, Object value3, Object value4)  
                  {  
                    PreparedStatement stat = null;  
                    try  
                    {  
                      String sql = "Insert into vdet (VID,LINEITEM,DEBITST,AMOUNT) values 
       ('" + value1 + "','" + value2 + "','" + value3 + "','" + value4 + "')";  
                      System.out.println("sql= " + sql);    
                      stat = getDBTransaction().createPreparedStatement(sql, 1);  
                      stat.executeUpdate();  
                    }  
                    catch (Exception e)  
                    {  
                      e.printStackTrace();  
                    }  
                    finally  
                    {  
                      try  
                      {  
                        stat.close();  
                      }  
                      catch (Exception e)  
                      {  
                        e.printStackTrace();  
                      }  
                    }  
                  }  
                  
                  private void updateSecondRowInDatabase(Object value1, Object value2, Object value3, Object value4)  
                  {  
                    PreparedStatement stat = null;  
                    try  
                    {  
                      String sql = "update vdet set vid='"+ value1+"',lineitem='"+ value2+"',DEBITST='" 
       + value3 + "', AMOUNT='" + value4 + "' where VID='" + VID + "'";  
                      System.out.println("sql= " + sql);      
                      stat = getDBTransaction().createPreparedStatement(sql, 1);  
                      stat.executeUpdate();  
                    }  
                    catch (Exception e)  
                    {  
                      e.printStackTrace();  
                    }  
                    finally  
                    {  
                      try  
                      {  
                        stat.close();  
                      }  
                      catch (Exception e)  
                      {  
                        e.printStackTrace();  
                      }  
                    }  
                  }
    

    Now the problem is that when later I change the quantity and price of the first line isn't updated but second row, because I used the command

     <af:button actionListener="#{bindings.Commit.execute}" text="Commit"
    

    This button update the first line added by bean managed, but the second row remains unchanged.

    Please help how to update the two lines with the same button or something else.

    Concerning

    DML_UPDATE will call only if there is some change data attributes.

    I guess that the update statement is false because vid looks like a primary key for the table, then, how update you the primary key of the update statement and how the update condition statement where the vid = '0'

    I assume the update statement should look like:

      private void updateSecondRowInDatabase(Object value1, Object value2, Object value3, Object value4)
      {
        PreparedStatement stat = null;
        try
        {
          String sql =
            "update vdet set lineitem='" + value2 + "',DEBITST='" + value3 + "', AMOUNT='" + value4 +
            "' where VID='" + value1 + "'";
          System.out.println("sql= " + sql);
          stat = getDBTransaction().createPreparedStatement(sql, 1);
          stat.executeUpdate();
        }
        catch (Exception e)
        {
          e.printStackTrace();
        }
        finally
        {
          try
          {
            stat.close();
          }
          catch (Exception e)
          {
            e.printStackTrace();
          }
        }
      }
    
  • In the course of my recent upload Lightroom 5 on my Macbook I bought recently with the serial number of the disk that I bought the year last for my Windows PC (an update of Lightroom 4) of the license.  I have an error message "you entered the serial numb

    In the course of my recent upload Lightroom 5 on my Macbook I bought recently with the serial number of the disk that I bought the year last for my Windows PC (an update of Lightroom 4) of the license.  You receive an error "the serial number you entered is invalid."  Why does CC not recognize this as a serial number valid?

    Soyouca how did you install Photoshop Lightroom?  Please uninstall the current installation by using the uninstall program located in Applications/Utilities/Adobe Installers.

    Once Photoshop Lightroom is deleted please download a new copy of the installation files of Adobe - Lightroom: for Macintosh.  The update contains the full installer then please download the latest version of Photoshop Lightroom 5.

    You may be asked to enter your serial number for Photoshop Lightroom 4.  You can find information on how to locate the serial numbers under your account to find your serial number fast - http://helpx.adobe.com/x-productkb/global/find-serial-number.html.

  • Restrictions does not not after ISO put 10.0.1 update with the new iPhone 7

    Restrictions does not after ISO put 10.0.1 update with the new iPhone 7 any which option of ranking app I don't choose no changes are made.  All the patches?

    Thank you

    Hello Launcher,

    Thank you for bringing your question about Restrictions here in Apple Support communities. My understanding of your question is that you change the Restrictions, but no change is noticed. I tried the same on my iPhone 6 Plus running iOS 10 and noticed a similar situation. Please allow me the opportunity to explain how the Restrictions is designed to work. First, I put my limitations for applications, do not allow Apps and together 4 +, which basically means everything beyond 4 + will be blocked from buying. Then I went to the App Store and the first app that caught my attention was NCIS: hidden crimes. This app is rated 12 + and is definitely an application I would not want my toddler to help. It is that Restrictions come into play. When I type on NCIS: hidden Crimes, the Get option is grayed out. Restrictions does remove all apps, songs, books, etc. from view, but it will prevent the purchase, download, and install all applications rated above the setting you choose when you set up restrictions. It's the help article that discusses the Restrictions and prevent purchases: Use Restrictions in order to avoid buying on iPhone, iPad, or iPod touch.

    I checked on the restrictions help articles, and I understand where it can be a bit confusing. In the help article Use Restrictions on iPhone, iPad and iPod touch, it says "You can use Restrictions, also known as parental control, to block or limit specific applications and features on your iPhone, iPad or iPod touch." This means in fact that apps, features or services (rated above that helped you, or if you have turned off completely) can he no longer appears on the device if the restriction is activated and starts blocking them. I also tested this by activating Restrictions and turned the cursor for Safari to off. When I went back to the home screen, Safari doesn't show any more and I could no longer use it.

    I hope this helps to clarify how the Restrictions. If my understanding of the issue was not accurate to the issue that you are experiencing, I will be happy to pursue this issue with you. Please indicate exactly what you took measures, and what expectations you had or the some restrictions, applications, features, or services you are restricted. Thanks again and have a great rest of your day!

  • I bought an iphone used several years ago... hen his recently updated with the new iOS 7.1.2 it was locked with the previous owners account.how can I use my iphone is back with my apple and pass

    I bought an iphone used several years ago... When updating with the new iOS 7.1.2 recently, he was locked with previous apple owners account.

    its now useless. I didn't know all these crappy activation locks and all.now I have no idea

    How can I find my iphone is off and use my phone back

    iphone 4 32 gb

  • Bug in reporter Panel updated with the property Value Chart

    Hi guys,.

    Defer to what the Panel update property is set to true and chart is updated with the help of node "Property value", data are not updated graphics. Capture of the block diagram and VI (2014) screen gasket.

    Is this a known bug, and is there any fix for it?

    Thank you

    Knockaert

    I have not tried running your code, but here are some possible solutions:

    1. There is a primitive to write the value of a control by index (added in ~ 2013). This is designed to be used others live too and should work like a local.
    2. You can send data using another way (like a queue, etc.).
    3. Use the Ctl Val.Set method.
    4. Do not use a chart. Use a chart and manage the buffer yourself. You can find some examples if you're looking for graph XY.
  • Please help me understand how to install updates with the following error updated Message__The following have not been installed: __Security update for Microsoft XP KB 2289162

    Please help me understand how to install updates with the following error Message

    The following updates were not installed:

    Security for Microsoft XP KB 2289162 update

    See the section "How to get help" of http://support.microsoft.com/kb/2289162

    For individuals, please visit the Microsoft Solution Center and antivirus security for resources and tools to keep your PC safe and healthy.  If you have problems with the installation of the update itself, visit the Microsoft Update Support for resources and tools to keep your PC updated with the latest updates.

    Buying to meet problems installing Microsoft security updates also can visit the following page for assistance: https://consumersecuritysupport.microsoft.com/

    ~ Robear Dyer (PA Bear) ~ MS MVP (that is to say, mail, security, Windows & Update Services) since 2002 ~ WARNING: MS MVPs represent or work for Microsoft

  • I am also having the same problem with the same updates. I have Windows XP SP3 and it's updates with the problem.

    I am also having the same problem with the same updates. I have Windows XP SP3 and it's updates with the problem.

    Security Update for Microsoft .NET Framework 2.0 SP2 on Windows Server 2003 and Windows XP x 86 (KB2572073)
    A security update for .NET Framework 2.0 SP2 and 3.5 SP1 on Windows Server 2003 and Windows XP x 86 (KB2518864)
    Security Update for Microsoft .NET Framework 2.0 SP2 on Windows Server 2003 and Windows XP x 86 (KB2633880)

    They all install properly but switches back to windows update to install. It's some kind of loop.

    Hi billy73,

    In addition, if you still have questions, please take a look at the thread similar here with a solution as possible.

    I hope this helps!

  • kb2633171 a security update wont install windows vista and keeps on saying failed in the history of updates with the error code 80070020

    Original title: kb2633171 security update will not install windows vista

    Hello

    as noted above, the kb2633171 of security update will not install on my computer used windows vista laptop. I had mcafee installed since the first day (it came with the pc). He continues saying failed in the history of updates with the error code 80070020. When I restart the pc, it says that it cannot configure the update and it is up to the old settings.

    I ran the fix it and aggressive to solve this problem, no luck :-(

    any help muchly appreciated.
    Thank you!

    Chiara

    Hi Chiara,

    Try following the steps in the following article.

    You receive error 0 x 80070020 when you use the Windows Update Web site or the Microsoft Update Web site to install the updates

    http://support.Microsoft.com/kb/883825

     

    Let us know if it helps.

  • Email with attached video will not leave the Outbox... Cannot delete Email with the attached video.

    Email with attached video will not leave the Outbox... Cannot delete Email with the attached video.

    Check to work offline , and then it should delete.

Maybe you are looking for