Update trigger that inserts the record in another table

I searched the forum and the web for an example like this and I can not find a:

A field is updated in the TABLE_A and it triggers a single record TABLE_B insert that has the old and the new value of the field.

I write a lot of complex data warehouse SQL-based reports, but very rarely do much PL/SQL, any help would be appreciated.
Thanks in advance.

Hello

You can specify that the trigger should fire only when certain columns are referenced, like this:

create or replace trigger test_fund_trig
before update OF FUNDING
on table_a
...

If you do this, the trigger will not draw on statements such as:

UPDATE  table_a
SET     mod_date = SYSDATE;

You should always use an IF statement, as I mentioned earlier, if you do not want to follow the updates where the value of this column has not really changed.

Tags: Database

Similar Questions

  • Insert the record of one table to another with the help of the cursor

    Help, please!

    the tables are - 1. countries (country_id pk, country_name, region_id)
    2A (country_id, country_name, region_id)
    table data are
    1 to 1
    2 b 2
    3 C 3
    NULL d 4
    5 e 5
    6 f 6
    7 g 7
    -----------------------
    Insert the record in the table a country table with the help of the cursor, insert all the non-null records.
    This procedure does not correct result
    -----------------------

    create or replace
    Amit procedure as
    cursor c1 is select * from a;
    RW a % rowtype;
    Start
    Open c1;
    Fetch c1 into rw.
    While (C1% found)
    loop
    insert into countries values (rw.country_id, rw.country_name, rw.region_id);
    commit;
    Fetch c1 into rw.
    If rw.country_id is null then
    Fetch c1 into rw.
    end if;
    end loop;
    Close c1;
    exception
    while others then
    dbms_output.put_line ('exception = name ' |) RW.country_name);
    end;

    You don't need cursor at all;

    create or replace procedure amit as
    
    begin
      insert into countries (Country_ID, Country_Name, Region_ID)
      (select a.Country_ID
             ,a.Country_Name
             ,a.Region_ID
       from a
      );
    
      dbms_output.put_line('Rows inserted : ' || sql%rowcount);
    
      commit;
    
    end;
    /
    
  • Update of data based on records in another table

    I have 2 tables

    Table 1
    Name Date of article
    Jon apples 2013/06/11 00:30:00 hrs
    Sam Oranges
    NISH apples

    Table 2 - Net number
    Number of name components
    NISH apples 10
    NISH Oranges 17
    NISH banana
    Sam 10 apples
    Sam Oranges 1
    Sam bananas 1
    Jon potatoes 8

    I need to create a job that checks the table 1 for new records added after the last race and then add the count in table 2 accordingly.
    Please guide on how to do this using the PL/SQl or something similar

    You need a third table where you store the time stamp of the last execution or an additional field in table 1 which indicates if a record has been processed already. (or the Date column has this information?).

    Then he must know if all possible combinations of the name and are already in Table2. If so, a simple update would do the job. If this isn't the case, you should take a look at the merge statement:

    http://docs.Oracle.com/CD/B28359_01/server.111/b28286/statements_9016.htm

    Good bye

    DPT

  • by comparing the records with another table

    Hello
    I have the following 2 tables (test_prs & test_dep) and registers
    My goal is to compare test_prs with test_dep records and return the records that are not in test_dep

    Here is the table scripts
    create table test_prs (id ,p_id ,r_id)
    as
    select 1,200566,200566 from dual
     union all
    select 2,200567,200567
    from dual
    
    create table test_dep (id,de_typ,de_id,de_u_typ,de_u_id)
    as
    select 10,'AS',200566,'PG',200566
    FROM DUAL
    UNION ALL
    select 11,'AS',200567,'PG',200567
    FROM DUAL
    
    
    insert into test_dep 
    select 12,'AS',400189,'PG',400273 FROM dual union all
    select 13,'AS',400273,'PG',400250 FROM dual union all
    select 14,'AS',400273,'PG',400192 FROM dual union all
    select 15,'AS',400273,'PG',400191 FROM dual
    
    insert into test_prs
    select 3,400273,400273 from dual
    I tried the following query to meet my criteria. My output should be null, but all records
    select * from 
    test_prs  prs
    where  exists (select 1 from test_dep de where de.de_id !=prs.p_id and de.de_u_id !=prs.p_id )
    Could you please help me the same

    Published by: smile on 7 March 2012 15:00

    Smile says:
    Thanks for the request

    The query does not work with the following documents

    insert into test_dep
    select 16,'AS',750664,'PG',750758 FROM dual 
    
    insert into test_prs
    select 4,750758,750668 from dual
    

    the r_id should not be put in correspondence with the columns in the test_dep table. P_id must only be put in correspondence

    OK, you want to match against the de_id and the de_u_id p_id? Or a line where either p_id concordances r_id de_u_id or de_id must not be returned?

    To match p_id against de_id and de_u_id, you can write the query like this:

    select id, p_id, r_id from test_prs where
    p_id in
    (select p_id from test_prs
    minus
    select de_id from test_dep
    minus
    select de_u_id from test_dep);
    

    Brgds
    Johan

  • Need to create a trigger that generates multiple rows in another table

    {size: 12} Hello

    I use Oracle9i (9.2.0.4.0)

    My problem is:
    I need to create a trigger that create different in the other table lines when someone will introduce a new line in the first table.

    For this, I use the table 4:

    1. first one where you want the trigger.
    2. a second just to take information.
    3. a third to make a trip meter.
    4. the fourth is the table where I want to create new lines. {size}

    Here is a summary of these 4 tables:

    {color: blue} Table 1
    STOJOU
    Number ¿Nulo? Tipo
    STOFCY_0 NOT NULL VARCHAR2 (9)
    ITMREF_0 NOT NULL VARCHAR2 (60)
    LOT_0 NOT NULL VARCHAR2 (45)
    VCRTYP_0 NOT NULL NUMBER (3)
    VCRNUM_0 NOT NULL VARCHAR2 (45)
    VCRLIN_0 NOT NULL NUMBER (10)
    QTYSTU_0 NOT NULL NUMBER
    NUMVCR_0 NOT NULL VARCHAR2 (45) {color}

    {color: blue} Table 2
    ITMMASTER
    Number ¿Nulo? Tipo
    ITMREF_0 NOT NULL VARCHAR2 (60)
    ZCOEFI_0 NOT NULL NUMBER {color}

    {color: blue} Table 3
    ZCTUART;
    Number ¿Nulo? Tipo
    CTUART_0 NOT NULL NUMBER (10)
    CTUDATE_0 NON NULL DATE {color}

    {color: blue} Table 4
    ZUART
    Number ¿Nulo? Tipo
    ZUARTDM_0 NOT NULL VARCHAR2 (102)
    STOFCY_0 NOT NULL VARCHAR2 (9)
    STOCOU_0 NOT NULL NUMBER
    ITMREF_0 NOT NULL VARCHAR2 (60)
    LOT_0 NOT NULL VARCHAR2 (45)
    CREDAT_0 NOT NULL DATE
    QTYSTU_0 NOT NULL NUMBER
    STA_0 NOT NULL VARCHAR2 (3)
    VCRLIN_0 NOT NULL NUMBER (10)
    VCRNUM_0 NOT NULL VARCHAR2 (45)
    VCRTYP_0 NOT NULL NUMBER (3) {color}

    I do this trigger:
    CREATE OR REPLACE TRIGGER CREA_REGISTROS_TRAZA
    AFTER INSERT ON STOJOU
    FOR EACH ROW
    DECLARE
       n INTEGER;
       ct NUMBER;
       fecha_actual VARCHAR2;
       fecha_old VARCHAR2;
       codigo_dm VARCHAR2;
    BEGIN
       fecha_actual := TO_CHAR(SYSDATE, 'DD/MM/YYYY');
       -- SELECT TO_CHAR(sysdate, 'DD/MM/YYYY') INTO fecha_actual FROM DUAL;
       SELECT TRUNC((STOJOU.QTYSTU_0/ITMMASTER.ZCOEFI_0),0) INTO n FROM STOJOU INNER JOIN ITMMASTER ON STOJOU.ITMREF = ITMMASTER.ITMREF;
          FOR i IN 1 .. n
       LOOP
          SELECT CTUART_0,TO_CHAR(CTUDAT_0, 'DD/MM/YYYY') INTO ct,fecha_old FROM ZCTUART;
          IF fecha_old <> fecha_actual THEN
            ct := 0;
          END IF;
          ct := ct + 1;
          INSERT INTO ZCTUART
            (CTUART_0,CTUDAT_0)
          VALUES
            (ct,SYSDATE);
          codigo_dm := SUBSTR('000000000000000000000',1,20 - LENGHT(NEW.ITMREF_0)) || NEW.ITMREF_0 || SUBSTR('0000000000',1,10 - LENGHT(NEW.LOT)) || NEW.LOT || SUBSTR('0000',1,4 - LENGHT(ct)) || ct;
          INSERT INTO ZUART
            (ZUARTDM_0,ITMREF_0,CREDAT_0,STA_0,QTYSTU_0,LOT_0,STOFCY_0,VCRLIN_0,VCRNUM_0,VCRTYP_0)
          VALUES
            (codigo_dm,NEW.ITMREF_0,SYSDATE,0,NEW.QTYSTU_0,NEW.LOT_0,NEW.STOFCY_0,NEW.VCRLIN_0,NEW.VCRNUM_0,NEW.VCRTYP_0);
       END LOOP;
    END CREA_REGISTROS_TRAZA;
    /
    {size: 12} And the error message I get States is just:
    "The trigger was created with compilation errors."
    Thanks for the help {size}

    You must prefix your NEW "columns" with a colon, as in: NEW.

  • to insert multiple records in another table

    Hi all;

    How can I increase the number of records in the table?

    SQL > insert into tab2 to select * From tab1;

    Enter tab2 to select * From tab1

    *

    ERROR on line 1:

    ORA-00926: lack of keyword VALUES

    Hi try this...

    Insert in tab2 select * from tab1

  • How to create a table with a column that is the value in another table?

    Hi all,

    It's my first post n I changed my ODI of DATASTAGE platform. Help me friends n I know basic steps in 11 ODI version which I was training in my company. I hope to have your support and can do everything an action ODI related documents.

    My question is...

    Table T1 > > > > > > > > > >

    service id / / / attr.name / / / attr.value

    S1 / / / product_code / / / P1

    S1 / / / provider / / / pro1

    S2 / / / product_code / / / P2

    S3 / / / provider / / / pro3

    Table T2 > > > > > > > > > > > > > > >

    ID / / / product_code / / / provider

    S1 / / / p1 / / / pro1

    S2 / / / p2 / / / nullvalue

    S3 / / / nullvalue / / / pro3


    I have a table T1 since I should show the table T2 is released. Can we say everything on how to write a logic and steps to follow.

    Thanks in advance.

    Published by: 854662 on April 26, 2011 01:59

    Hello

    U go.

    1 the interface:

    "Put a filter in your 1 on attr.name = array ' PRODUCT_CODE.

    In the map target TABLE2
    SERVICE_ID = TABLE1. SERVICE_ID
    PRODUCT_CODE = TABLE1. ATTR_VALUE

    Use SQL IKM append control

    Interface 2:

    "Put a filter in your 1 on attr.name = array ' PROVIDER '.

    In the map target TABLE2
    SERVICE_ID = TABLE1. SERVICE_ID
    PROVIDER = TABLE1. ATTR_VALUE

    Do SERVICE_ID as KEY (when you click the column target in properties, you can see KEY under properties of the target column) and use the incremental update of the IKM Oracle.

    PS: I assume that Oracle as the source and target.

    And you can refer to the documentation,

    https://Apex.Oracle.com/pls/Apex/f?p=44785:24:4413167952886630:no:24:P24_CONTENT_ID, P24_PREV_PAGE:5185, 29

    http://odiexperts.com/

    And of course this OTN.

    Thank you
    Guru

  • Insert the records of 2 tables in tables.

    Hi all
    I have 3 tables as below
    SQL > desc a1
    Name Null? Type
    ----------------------------------------- -------- ----------------------------
    COL1 NUMBER (20)
    COL2 VARCHAR2 (10)

    SQL > desc a2
    Name Null? Type
    ----------------------------------------- -------- ----------------------------
    COL1 NUMBER (20)
    COL2 VARCHAR2 (10)

    SQL > c1 desc;
    Name Null? Type
    ----------------------------------------- -------- ----------------------------
    COL1 NUMBER (20)
    COL2 VARCHAR2 (10)

    Now, I want to insert records from a1 and a2 in c1 with the help of a unique sql. Please can someone give me the sql statement.

    Thank you...

    Hello

    Example:

    insert into tab3
    select * from tab2
    union all
    select * from tab1;
    

    Bartek

  • delete all the records in a table, the speed of insertion is not change.

    I have an empty table, and I insert a record need 100ms.
    During this table a 40,0000 trace, I insert a record need 1 s, it's ok, because I need to make a comparison according to an index before inserting a record need, so more record, more time.
    The problem is when I delete all the record in this table, the insertion time is always 1s, not reduce to 100ms. Why?

    Hello

    Read this part of the oracle documentation

    http://download.Oracle.com/docs/CD/B19306_01/server.102/b14220/logical.htm#CNCPT004

    The reason is always 1s, because when you inserted 400ko record as HWM (high tide is the border between old and new space in a segment.) moved to the top. And when you remove all records of your HWM still in the same coordinate system and that you have not reset to 0. So when you insert 1 it save free space and after finding faces (usually a regular insertions got 6 steps it inserts data). If you truncate your table you and try it again it will be faster that your HWM is reset to 0.

    Concerning

  • I have about 530 jpegs that were the records to progressive JPEG, and I need to save them all to standard baseline JPEG.  How to do all this without recording them one by one?

    I have about 530 jpegs that were the records to progressive JPEG, and I need to save them all to standard baseline JPEG.  How to do all this without recording them one by one?

    Hi Rachel

    Go file > Scripts > Image Processor which opens this Panel

    It will be easier if you put all the images in a folder, you can select this folder and all the files it contains batch. The numbered sections are in the order you need to follow, so nice an easy.  Don't forget to assign a location record well, or you might struggle to find their.

    An alternative, FI you re using Windows is Irfanview.   It has more options than the Image Processor, but maybe it's a little harder to use.

    http://www.IrfanView.com/

    Good luck

  • Insert the record type

    Hi all

    I created a table with two columns method. I am assigned two values to variable recordtype.
    When inserting the record in the table, a compiler error is to be there.
    Create table emp_info(empno number(5),ename varchar2(30));
    
    DECLARE
    
    l_rec emp_info%rowtype;
    
    BEGIN
    
    l_rec.empno := 101;
    l_rec.ename := 'KING';
    
    insert into emp_info(empno,ename)
    values(l_rec);
    
    commit;
    
    END;
    ERROR on line 11:
    ORA-06550: line 10, column 35:
    PL/SQL: ORA-00947: not enough values
    ORA-06550: line 10, column 1:
    PL/SQL: SQL statement ignored


    Can I insert with output Recordtype variables indicating the column names. Can someone help me?

    Do not list of columns. Do not put brackets in the record variable:

    SQL> DECLARE
      2      l_rec emp_info%rowtype;
      3  BEGIN
      4      l_rec.empno := 101;
      5      l_rec.ename := 'KING';
      6      insert
      7        into emp_info
      8        values l_rec;
      9       commit;
     10  END;
     11  /
    
    PL/SQL procedure successfully completed.
    
    SQL> 
    

    SY.

  • inserting multiple rows of another table with incremented recordid

    Hi all

    I HAVE TWO TABLES:

    CREATE TABLE TEMP_TEST1)
    NUMBER OF RECID,
    TESTCHAR VARCHAR2 (500)
    )

    AND

    CREATE TABLE TEMP_TEST2)
    TESTCHAR VARCHAR2 (500)
    )

    Both the table contains data in it. I want to insert data from TEMP_TEST2 in TEMP_TEST1 with RECID incremented for each record, which must be greater than max (RECID) of TEMP_TEST1.
    PS: I have to query insert only, I cannot make changes in the structure of table or RECID of TEMP_TEST1 is not automatically incremented.
    Please suggest a query that selects the record of TEMP_TEST2 and TEMP_TEST1 insert with recid incremented for each record.


    Thank you.
    SQL> insert into TEMP_TEST2(TESTCHAR)
      2  select 'Test'||level from dual connect by level < 10
      3  /
    
    9 rows created.
    
    SQL>
    SQL>
    SQL> insert into TEMP_TEST1(RECID,TESTCHAR)
      2  select (select nvl(max(RECID),0) from TEMP_TEST1) + rownum, t2.TESTCHAR
      3  from TEMP_TEST2 t2
      4  /
    
    9 rows created.
    
    SQL>
    SQL> select * from TEMP_TEST1
      2  /
    
         RECID TESTCHAR
    ---------- ----------
             1 Test1
             2 Test2
             3 Test3
             4 Test4
             5 Test5
             6 Test6
             7 Test7
             8 Test8
             9 Test9
    
    9 rows selected.
    
    SQL> insert into TEMP_TEST1(RECID,TESTCHAR)
      2  select (select nvl(max(RECID),0) from TEMP_TEST1) + rownum, t2.TESTCHAR
      3  from TEMP_TEST2 t2
      4  /
    
    9 rows created.
    
    SQL>
    SQL> select * from TEMP_TEST1
      2  /
    
         RECID TESTCHAR
    ---------- ----------
             1 Test1
             2 Test2
             3 Test3
             4 Test4
             5 Test5
             6 Test6
             7 Test7
             8 Test8
             9 Test9
            10 Test1
            11 Test2
    
         RECID TESTCHAR
    ---------- ----------
            12 Test3
            13 Test4
            14 Test5
            15 Test6
            16 Test7
            17 Test8
            18 Test9
    
    18 rows selected.
    
    SQL>
    

    Good bye
    DPT

  • How to make a value in a temporary table, the match against another table...

    Hi all.

    Please is - can someone provide some guidance on how to...

    1. take a value from a temporary table, the match against another table that contains the first values 'equivalent' value.
    2. take this exchange value, call something (using the slider or the variable?) so I can add to my API to load it into ORACLE...

    Apology of this sounds confusing, I hope you know everything what I want to do...

    Manythanks...

    Steven

    and call the API

    declare
       v number;
    begin
       SELECT oracle_loc_code
          into v
       FROM SU_IEXP_LOCATIONS
          , SU_TEMPLOYEE_DETAILS
       WHERE chris_loc_code =location_id
       ;
       Hr_Assignment_Api.update_emp_asg_criteria (v);
    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

  • trigger for update field in a table with the sum of the fields to another table

    My experience in creation of triggers and pl/sql in general can be described in terms of oracle with the null value. I practiced by creating arrays and applications on my personal server at home to help me with some of my work related tasks. Right now I am creating a trigger which will, after insert, update, delete on the update of the table assignment_time_track the area of the time_spent on the table of assignments with the sum of the time_spent on the assignment_time_track table fields. I hope that run on the sentence it is clear to the people other than me. I tried this script on my own using the tool of creation of trigger for Oracle Database Express Edition, but I get the following error:

    Create a trigger failed, for the following reason:
    ORA-06552: PL/SQL: ORA-06553 finished Compilation unit analysis: PLS-320: the declaration of the type of the expression is incomplete or incorrect

    Here is my attempt to create the trigger on my own.

    create or replace trigger "ASSIGNMENT_TIME_TRACK_T1".
    AFTER
    INSERT or update or delete on 'ASSIGNMENT_TIME_TRACK '.
    for each line
    Start
    update assignments
    Set time_spent = (select sum (time_spent)
    of assignment_time_track
    where assignment_time_track.name = assignments.name);

    end;
    /


    If what I posted is not clear or more detail is needed, let me know and I will respond with a full description of tables and my goals for each table. Thanks in advance for any help. I also gladly accepts links to tutorials or lessons that explain how to do this kind of thing.

    Published by: bobonthenet on March 9, 2009 14:01

    I think I understand what you mean :)

    Rather than use a trigger to keep the master table (assignments) in sync with the time spent on the details, it would be much easier to use a query to do this, maybe creating a view.

    Something along the lines of

    SQL> create table assignments
      2  (id number primary key
      3  ,name varchar2(10)
      4  );
    
    Table created.
    
    SQL>
    SQL> create table assignment_time_tbl
      2  (id number primary key
      3  ,assid number references assignments
      4  ,time_spent number
      5  );
    
    Table created.
    
    SQL>
    SQL> insert into assignments
      2  select rownum
      3       , 'a'
      4    from all_objects
      5   where rownum < 5
      6  /
    
    4 rows created.
    
    SQL>
    SQL> insert into assignment_time_tbl
      2  select rownum
      3       , rownum
      4       , rownum * 3
      5    from all_objects
      6   where rownum < 5
      7  /
    
    4 rows created.
    
    SQL>
    SQL> commit;
    
    Commit complete.
    
    SQL>
    SQL>
    SQL> select a.id
      2       , a.name
      3       , (select sum (time_spent)
      4            from assignment_time_tbl
      5           where assid = a.id
      6         )
      7    from assignments a
      8  /
    
            ID NAME       (SELECTSUM(TIME_SPENT)FROMASSIGNMENT_TIME_TBLWHEREASSID=A.ID)
    ---------- ---------- -------------------------------------------------------------
             1 a                                                                      3
             2 a                                                                      6
             3 a                                                                      9
             4 a                                                                     12
    

Maybe you are looking for

  • Can not get the new pair Apple wireless keyboard

    I followed the 'how' document, but it does not work - I guess that these statements applied to the previous generation apple wireless keyboard, but not the new series aluminum. When I "add new connection" (Express or Custom mode) a dialog box opens a

  • How can I recover deleted files without using any software?

    How can I recover deleted no matter what folder, image, Word & excel files without using any software inculd Recycle Bin?

  • Cannot connect to my Windows Vista system that my password do not work.

    MY TOSHIBA EQUIUM LT IS 6YO. I HAVE THE RECOVERY DISK. AN outfit that have been paid eighty-five pounds for the support of a year now claim to allow to recover my LT I need windows vista disks to ensure my ability to log on as administrator and user.

  • Installation of Windows 7 help - HP Pavilion 2800

    Hello I'm having quite the challenge with installing Windows 7.  I have a HP Pavilion dv2800 (2842se) (Vista 64 - Bit), which required a new hard drive.  Today, I installed a new SATA 320 GB 5 400 rpm device and booted up using the Windows 7 installa

  • Cannot download updates windows for windows 7

    Hello I'm having problems trying to download the updates of windows to windows 7. I have the 64 - bit version operating system. Whenever I click on "check for updates" it hangs there forever, and I finally to close the screen. I looked for solutions