How to write the trigger for update or delete multiple columns in a table?

Hello

I create one in the form of table of sample_emp. In that, every time I want to change of name, team_id, team_leader_id, supervisor_id, manager_id it must store the update-able and old values of those in the job_history table. When I write the trigger for which it shows "ORA-04082 new or the old value not table level triggers. Here is my emp_table. My table also similar job_history like this. Need your help.

Header 1 Header 2 Header 3 Header 4 Header 5 Heading 6 Heading 7 8 header Header 9
EMP_IDEMP_NAMEDESIGNATIONTEAM_IDTEAM_LEADER_IDEMPLOYEEMANAGER_IDHIRE_DATERELIEVED_DATE

--

Thank you.

Hi Joel,.

Venky_prs wrote:

Hello

I create one in the form of table of sample_emp. In that, every time I want to change of name, team_id, team_leader_id, supervisor_id, manager_id it must store the update-able and old values of those in the job_history table. When I write the trigger for which it shows "ORA-04082 new or the old value not table level triggers. Here is my emp_table. My table also similar job_history like this. Need your help.

Header 1 Header 2 Header 3 Header 4 Header 5 Heading 6 Heading 7 8 header Header 9
EMP_ID EMP_NAME DESIGNATION TEAM_ID TEAM_LEADER_ID EMPLOYEE MANAGER_ID HIRE_DATE RELIEVED_DATE

--

Thank you.

You can try something like this given below to complete the historical table on update and delete.

create or replace TRIGGER  "CLONE_EMP_UPDATE_DELETE"
BEFORE DELETE OR UPDATE ON EMP
FOR EACH ROW
DECLARE
    PRAGMA autonomous_transaction;
BEGIN
INSERT INTO JOB_HISTORY("EMP_ID","EMP_NAME","DESIGNATION","TEAM_ID","TEAM_LEADER_ID","SUPERVISOR_ID","MANAGER_ID"
,"HIRE_DATE","RELIEVED_DATE")
  VALUES(:OLD.EMP_ID,:OLD.EMP_NAME,:OLD.DESIGNATION,:OLD.TEAM_ID,:OLD.TEAM_LEADER_ID,:OLD.SUPERVISOR_ID,
:OLD.MANAGER_ID,:OLD.HIRE_DATE,
:OLD.RELIEVED_DATE);
COMMIT;
END;

Hope this helps you,

Kind regards

Jitendra

Tags: Database

Similar Questions

  • How to write the trigger for update of 2 tables

    Hi all
    I have 2 tables,

    1.lv_data,
    It contains the following fields,
    emp_name        tot_days
     guru                    18
                
    2.leave_data
    It contains the following fields,
     emp_name          From_date              to_date            no_of_days       remaining_days
     guru                    02/05/2012          03/05/2012           2                         
    In the second table, if the data is inserted.
    the no_of_days will be calculated automatically (from to_date - From_date) + 1,

    Here, I need to write the trigger to update the remaining_days column,

    First table for all tot_days emp_name is 18 days,
    Thus, in the second table every time that the record is inserted.
    the remaining_days must be calculated as follows,

    remaining_days: = tot_days - no_of_days and this (calculated) value should be updated in the tot_days column in the first table (lv_data).

    Example:
    emp_name        tot_days
    guru                    18
                
    2.leave_data
     emp_name          From_date              to_date            no_of_days        remaining_days
     guru                    02/05/2012          03/05/2012         2                          16
    [/code  
    
    Now the first table should be updated like,
    emp_name tot_days
    Guru 16


    So I need to update to 2 tables,
    can someone help me to update these 2 tables through TRIGGER?

    Thank you
    Kind regards
    gurujothi

    Edited by: Gurujothi may 1, 2012 19:54

    It is generally considered bad practice to store the value even in 2 places. You are having the kind of problems that you are experiencing now. It is much easier to store in the main table and get the value from there where you need to show in your forms.

  • How can I write the trigger for the global temporary Table

    Hi Grus,
    How can I write the trigger for the global temporary Table.

    I created the TWG with trigger using the script below.


    CREATE A GLOBAL_TEMP GLOBAL TEMPORARY TABLE
    (
    EMP_C_NAME VARCHAR2 (20 BYTE)
    )
    ON COMMIT PRESERVE ROWS;


    CREATE OR REPLACE TRIGGER TRI_GLOBAL_TEMP
    BEFORE DELETE, UPDATE OR INSERT
    ON GLOBAL_TEMP
    REFERRING AGAIN AS NINE OLD AND OLD
    FOR EACH LINE
    BEGIN
    INSERT INTO VALUES EMPNAME (: OLD.) EMP_C_NAME);
    END;
    /


    trigger was created successfully, but her would not insert EMPNAME Table...

    Please guide if mistaken or not? If not wanting to give a correct syntax with example


    Thanks in advance,
    Arun M M
    BEGIN
    INSERT INTO EMPNAME VALUES (:OLD.EMP_C_NAME);
    END;
    
    you are referencing old value in insert stmt.
    
    BEGIN
    INSERT INTO EMPNAME VALUES (:new.EMP_C_NAME);
    END;
    

    then run your app, it works very well...

    CREATE GLOBAL TEMPORARY TABLE GLOBAL_TEMP
    (
    EMP_C_NAME VARCHAR2(20 BYTE)
    )
    ON COMMIT PRESERVE ROWS;
    
    CREATE OR REPLACE TRIGGER TRI_GLOBAL_TEMP
    BEFORE DELETE OR UPDATE OR INSERT
    ON GLOBAL_TEMP
    REFERENCING NEW AS NEW OLD AS OLD
    FOR EACH ROW
    BEGIN
    dbms_output.put_line(:OLD.EMP_C_NAME||'yahoo');
    INSERT INTO EMPNAME VALUES (:new.EMP_C_NAME);
    dbms_output.put_line(:OLD.EMP_C_NAME);
    END;
    /
    
    create table EMPNAME as select * from GLOBAL_TEMP where 1=2
    
    insert into GLOBAL_TEMP values('fgfdgd');
    commit;
    select * from GLOBAL_TEMP;
    select * from EMPNAME;
    
    output:
    1 rows inserted
    commit succeeded.
    EMP_C_NAME
    --------------------
    fgfdgd               
    
    1 rows selected
    
    EMP_C_NAME
    --------------------
    fgfdgd               
    
    1 rows selected
    

    He got Arun

    Published by: OraclePLSQL on December 28, 2010 18:07

  • How to use the trigger for Hammer

    Hello

    I used a hammer and an accelerometer of pcb to do some tests of beam. I want to express signal for start of log data after I use the hammer hit something. Here is my configuration in express signal.

    Trigger type: analog edge. Source of relaxation: the channel of the hammer
    Slope: fall. Level: 0

    However, once he began to run, it says "logging was stopped because an error occurred with a step in the project. If this error is due to a device buffer overflow, you can improve performance by disabling updates to screen using the "view > views of Signal update during the race" menu item. You can also change the way in which the signals are recorded by changing the Logging Options in the tools > Options dialog box. Disabling "Prepare the log for display data" will greatly improve performance. "I've changed everything, but it didn't work.

    Should I use other types of trigger?

    Thank you
    Ningyu


  • How to write the function for bottom of logic...

    I have a picture in the picture I have a records like below
    code value
    1 20
    2 null
    3 30
    4 null
    5 40
    6 null


    The output need to have the values displayed in the fields first, followed by the NULL values as below

    code value
    1 20
    2 30
    3 40
    4 null
    5 null
    6 null

    I think the suspicion is that the values must be concatenated with the replacement of NULL values with (;).
    as
    20, 30, 40
    Get single values and insert into the table...

    for this I don't know how to write function for who can please help me on these...

    Published by: Claudia on June 22, 2011 22:45

    Published by: Claudia on June 22, 2011 22:51

    Create or replace function test_fun
    is
    cursor fun1 is the value select from table by CSA 2;-"this select query will return 20,30,40, null, null, null".
    v_out varchar2 (20);
    Start
    fun1 open cursor;
    loop
    extract the fun1 in v_out;
    dbms_output.put_line (v_out); - this is the command display output on the screen.
    output when fun1 not found %;
    end loop;
    close;
    end;

    Please try it and tell us if no query...

    Thank you
    IQ

  • How to design a trigger to update only if a column value is changed?

    Hello

    I have a nice little trigger that updates the CARD table when the table is updated. This table is updated within a master/detail form. It's the main table.
    Relaxation is used mainly to update the columns 'FICHE_MODIFIEE_PAR' (in English, it means "modified by") and "DATE_MODIFICATION" (in English, it means 'date modified'). I wish that these columns updates ONLY when the values in the columns 'TOTAL_HEURES' and 'TOTAL_HEURES_EXCEPTIONNELLES' are changed. These two columns have a default value for the number 0. That means that these columns change means change it value from the value 0 by default with another value or a value to another value. If the value of one or two of these two columns changes, the trigger must be fired for updating the column 'FICHE_MODIFIEE_PAR' and 'DATE_MODIFICATION '.
    create or replace TRIGGER  OBSERVATOIRE.TIB_FICHE
      before insert or update on OBSERVATOIRE.FICHE
      for each row
    begin
        if inserting and :new.fiche_id is null then
            select FICHE_SEQ.NEXTVAL INTO :new.FICHE_ID from dual;
        end if;
        if inserting then
            :new.fiche_cree_par := v('USER');
            :new.date_creation := sysdate;
        end if;
        if updating then
            :new.fiche_modifiee_par := v('USER');
            :new.date_modification := sysdate;
        end if;
    end; 
    Thank you for your help.

    Christian

    Hello Christian,.

    You can reference and compare the old and new values. For example
    IF: NEW. TOTAL_HEURES <> : OLD. TOTAL_HEURES OR: NEW. TOTAL_HEURES_EXCEPTIONNELLES <> : OLD. TOTAL_HEURES_EXCEPTIONNELLES
    THEN
    do your stuff
    END IF;

    Greetings,
    Roel

    http://roelhartman.blogspot.com/
    http://www.bloggingaboutoracle.org/
    http://www.Logica.com/

  • How can, during the collection of data, start a new column in my table every 100 data points?

    Hello! I have a problem with my data - I get in a wide range of 1 x 1000, but it's the repeated measures, each taking about 500 data points. I want to break this table for this data string start a new column in my table every 500 points given. I don't know how to do it-please help!

    datacompiler100 wrote:

    Hey thanks for the sponsor and the first off I must apologize for the State, I am attaching my VI. I put the part of the VI that I am working on (my team has access, so didn't post everything here) and also attached the data file (when just written in a spreadsheet file, not through the attached VI). I want to convert the long row of data and then start a new column every 50, 100, 5 points (user-defined).

    Using the data from the file, you can reshape everything simply (as you already!), followed by transposition (since you want columns instead of rows). 2D arrays must always be rectangular, so the last column is filled with zeros if necessary. Is that what you want?

    Of course if you try to add a new column in a file, that will not work. You can only add lines in an existing file because of the way the data is organized. To add columns, the entire file must be read, intertwined and all re-written new data in the file.

  • How to create the widget for updated by the customer?

    At the last moment, I used the widget of composition for the addition of new food for some clients. And right now, they would like to add the news that feed themselves.

    I try to find a different widgets that he can be there. Please answer me.

    00.JPGClick on the orange words to show the details01.JPGdetails is in the orange box which is the tootips widget.

    This message is marked as are answered, you always face the same problem?

    Thank you

    Sanjit

  • How to identify the buttons for forms in rows not columns

    Hello

    I have a long questionnaire with 100 lines.

    column 1 is the question.  Column 3, 4, 5 and 6 are responses of buttons (none, moderate, mild, extreme).  Buttons, which means only one answer allowed per line.

    There are headers for the buttons.    When this excel spreadsheet to adobe acrobat conversion - works.   But after creating a form buttons are labeled by column not online, then... they are not the true option by row buttons.   In other words, that one response per column is allowed, the opposite of what I want.

    How to solve this?   I change this by the original format or some global change?  There are a total of 100 buttons.  Much too laborious to change each one individually.


    Thank you.

    Yet once you create an option button or check box field. Then copy this field 5 times and place as needed. This should give you a line of 5 boxes or option of checkboxes with the same name. Now for each button field, right-click the field and select the 'Properties' option in the context menu. Select the 'Options' tab and assign a different value to the value of the option or the value of the exports. This means that you EF the same value for the fields in a given column.

    As a suggestion, start with a small form and see how the system works.

    From my experience of conversion Excel 'shape' a PDF form is not the best approach.

  • How to write a query for the data exchange between two columns?

    How to write a query for the data exchange between two columns?

    I tried a request, does NOT work.
    update tmp t1 set t1.m1=t1.m2 and t1.m2=(select t2.m1 from tmp t2 where t2.student_id = t1.student_id)
    Thank you.

    Published by: user533361 on October 23, 2009 14:04

    Just plain and simple:

    update tmp t1
     set t1.m1=t1.m2,
         t1.m2=t1.m1
    /
    

    SY.

  • How to write a script for date get to the Clipboard

    Hi experts,

    How to write a script for date get to the Clipboard.

    the date format will be like this:

    05 - may

    respect of

    John

    Thanks guys, thanks Sanon

    I finally use the .bat doc

    like this:

    @@echo off
    for /f "delims =" % in (' wmic OS Get localdatetime ^ | find ".") "") Set "dt = %% a"
    the value "YYYY = % dt: ~ 0, 4%.
    the value "MM = % dt: ~ 4, 2%.

    If MM % is 01 set MM = January
    If % MM == 02 set MM = February
    If MM % is MM value = March 03
    If MM % is 04 MM value = April
    If MM % is 05 MM value = may
    If MM % is 06 MM value = June
    If MM % == 07 set MM = July
    If MM % is MM value = August 08
    If MM % is MM value = September 09
    If MM % is 10 MM value = October
    If MM % is 11A set MM = November
    If MM % is game MM 12 = December

    the value "DD = % dt: ~ 6, 2%.
    the value "HH = % dt: ~ 8, 2%.
    the value "Min = % dt: ~ 10, 2%.
    Set "s = % dt: ~ 12, 2%.

    Echo DD - MM HH % %% % Min | Clip

    It works

    respect of

    John

  • How to write the select query for it

    Hello

    I had an html form and the area I drop down and he needs to select several values in the drop-down box. When I select multiple values then I have to write the query to SQL select statement.

    When I try to write the select statement and trying to run I get the error message.

    Select * from Table

    where emo_no = '1,2,3 '.

    That's how I write the query please suggest me how to write the query to select several values in the drop-down box.

    Thank you

    Use the keyword sql 'in '.  If you don't know how, I've heard good things about the book Teach Yourself SQL in 10 Minutes by Ben Forta.

  • How to disable the AppStore offers updated app that does not exist on the ipod touch 5g ios 9 and Reset counter app

    Regularly I receive notifications of updated Brainiacs Sudoku which I had deleted Ipod Touch 5 g a long time ago.  I can't disable the app update counter until I have download the update.  So, how to disable the AppStore offers updated app that does not exist on the ipod touch 5g ios 9 and Reset counter of the application once and for all?

    Try to hide this purchase

    Hide and show purchases iTunes or iBooks on your Mac or PC - Apple Support

  • How to upgrade the driver for my video card?

    How to upgrade the driver for my video card?

    Most often when a device does not work, it's because the driver has been corrupted.

    Try reinstalling your.

    http://Windows.Microsoft.com/en-us/Windows7/update-a-driver-for-hardware-that-isn ' t-work correctly? SignedIn = 1

    http://captaindbg.com/how-to-update-drivers-on-Windows-7/

  • Windows 7 continues the search for updates

    Recently, I have restored my laptop to factory settings, and after you install the service pack 1 update, this does not block the search for updates.  I tried everything on this site but without success.  Help, please.  Thank you.

    The installation of the plant is the worst possible Windows, that no tech fan would go because of the bloatware and installation utility factory duplicate that interfere with better integrated in the operating system versions.  Corruption as it is so just wait until you make a clean reinstall Windows 7 .

    If you want to try to wrestle with the factory install, so first thing I "d to recover some lost performance is Clean Up Factory Bloatware. "  It also checks and fix the integrity of the installation itself, which is not only limited but damaged by bloatware.

    Then, if the problem run the troubleshooting Windows Update - Microsoft Windows Help tool

    Then, try to Reset Windows Update components.

    Finally, as a last resort, run the System Update tool .

    Let us know how it goes and if there are any questions or problems.

Maybe you are looking for

  • Favorite random, one at a time, change the records?

    My problem started with the previous version of Firefox, and continues with the version 26.0. My HP Compaq dc7800p convertible runs THAT XP Pro 2002 with Service Pack 3 installed. I'm going to look for a particular bookmark, and it will not be in the

  • Toshiba virtual Store account Reset - 33401

    Hello Please you can reset account 33401 Thank you

  • I try to connect the Qosmio F20 for TV

    Hello I'm trying to connect my laptop to TV F20.Using S-video - cable Compositshown in pic blew :-| http://aycu32.Webshots.com/image/21471/2000131229832581606_rs.jpgATTENDANT: to display in my laptop on the TV. But infortunaly doesn't worke with me.C

  • Accuracy of measurement of the SCXI-1100 module

    Dear team, I'm figuring an accuracy of measurement for SCXI-1100 (http://digital.ni.com/manuals.nsf/websearch/0790D3C92CF4B16E8625665E00712865) devices. It is not described in the standard table, it has precision stage of entry / exit (must be added?

  • Cannot install programs

    Original title: windows problem whenever I try to install or open a program it dosnt continue up to the end .it stops between the two and no porgram does work I have windows xp .to cause of this problem I can't install or open any program that I have