trigger + follow level column changes

Hi all

I have some paintings
CREATE TABLE emp_details
  ( emp_number NUMBER, emp_name VARCHAR2(100)
  );
CREATE TABLE emp_address
  (
    emp_number   NUMBER,
    emp_state    VARCHAR2(100),
    emp_district VARCHAR2(100),
    emp_pin      NUMBER
  );
CREATE TABLE emp_contact
  (
    emp_number NUMBER,
    mobile     NUMBER,
    office     NUMBER,
    email      VARCHAR2(100)
  );
Now, I have to follow the exact changes for all tables for all columns.

So I intend to make my picture of history as
CREATE TABLE emp_hist
  (
    emp_number     NUMBER,
    column_changed VARCHAR2(30),
    new_value      VARCHAR2(100),
    old_value      VARCHAR2(100),
    changed_by     VARCHAR2(100),
    changed_time DATE
  ) ;
So I intend to create the trigger on each table to fill the record in the table hisory. but I'm a little confused. In the case where multiple columns are updated simultaneously so how can I write the trigger?

Any help or a better idea?

Presumably, if several columns change, you will need to insert several lines in the history table. It is usually a bad way to follow the story. Eventually generate a so many lines that it becomes very difficult to manage and query and you can join the table to itself several times in order to understand what a particular line looks like at some point in time.

If you are determined to follow the story in this way, you could do something like

CREATE TRIGGER emp_addr_trg
  BEFORE UPDATE ON emp_address
  FOR EACH ROW
BEGIN
  IF UPDATING( 'EMP_STATE' )
  THEN
    INSERT INTO emp_hist( emp_number, column_changed, new_value, old_value, changed_by, changed_time )
      VALUES( :new.emp_number, 'EMP_STATE', :new.emp_state, :old.emp_state, user, sysdate );
  END IF;

  IF UPDATING( 'EMP_DISTRICT' )
  THEN
    INSERT INTO emp_hist( emp_number, column_changed, new_value, old_value, changed_by, changed_time )
      VALUES( :new.emp_number, 'EMP_DISTRICT ', :new.emp_district, :old.emp_district, user, sysdate );
  END IF;

  IF UPDATING( 'EMP_PIN' )
  THEN
    INSERT INTO emp_hist( emp_number, column_changed, new_value, old_value, changed_by, changed_time )
      VALUES( :new.emp_number, 'EMP_PIN ', :new.emp_pin, :old.emp_pin, user, sysdate );
  END IF;
END;

He'll write a line for each column that is part of the update statement. You can add additional predicates to check to determine if the value is actually change (i.e. that the: new.column_name! =: old.column_name with proper management of NULL values if the column allows it).

Justin

Tags: Database

Similar Questions

  • need help to trigger to update the change of columns of a table

    Hi all
    I need help in the manufacture of change update trigger in the columns from one table to another table.
    For example, table (col1 col 2 col 3 col 4 col 5 samplea
    .. .Col 20

    Now if I do any change in one of the data column must be changed to
    sample_copya... table that contains duplicate column

    So for this I thought to create a trigger with the following logic



    If updating (col1) then
    Update sample_copya set col1: =: new.col1 where n ° 1 =: new.no1;
    Otherwise, if the update (col2) then
    Update sample_copya set col2: =: new.col2 where n ° 1 =: new.no1;
    Otherwise, if the update (col3) then
    Update sample_copya set col3: =: new.col3 where n ° 1 =: new.no1;

    end if;
    But how doi handle if all columns are changed or say 2 columns record the number of columns is more than 20...
    I would like to know if there is a simpler method to achieve...
    Thank you

    susf wrote:
    Hi all
    I need help in the manufacture of change update trigger in the columns from one table to another table.
    For example, table (col1 col 2 col 3 col 4 col 5 samplea
    .. .Col 20

    Now if I do any change in one of the data column must be changed to
    sample_copya... table that contains duplicate column

    So for this I thought to create a trigger with the following logic

    If updating (col1) then
    Update sample_copya set col1: =: new.col1 where n ° 1 =: new.no1;
    Otherwise, if the update (col2) then
    Update sample_copya set col2: =: new.col2 where n ° 1 =: new.no1;
    Otherwise, if the update (col3) then
    Update sample_copya set col3: =: new.col3 where n ° 1 =: new.no1;

    end if;
    But how doi handle if all columns are changed or say 2 columns record the number of columns is more than 20...
    I would like to know if there is a simpler method to achieve...
    Thank you

    What is the purpose of this trigger?
    How can you be sure that ' where n ° 1 =: new.no1 "is true?
    How does line in the SAMPLE_COPYA table at the start?
    only the last modified value will lie in SAMPLE_COPYA than the previous values is written more

  • After setting the brightness of the screen to the medium level, it change to the lower level after a few minutes.

    Original title: adjustment of the brightness of the display

    I have Lenovo laptop with Windows Home Premium. After setting the brightness of the screen to the medium level, it change to the lower level after a few minutes. Why can't I corrected the brightness of the display to the level I want?

    Hello

    I understand that you are facing problems with the brightness of the display. I understand the inconvenience.

    1. did you of recent changes to the computer before the show?

    2. What is the number of the model of the computer?

    Let us perform the following methods and check if it helps to solve the problem.

    Method 1: Try the Aero Troubleshooter

    Click Start, type Visual and then click on 'Find and Fix problems with transparency and other Visual effects.

    Follow this troubleshooter to see if that fixes the problem.

    Method 2: Uninstall and reinstall video graphics driver

    Update drivers:

    http://Windows.Microsoft.com/en-us/Windows7/update-drivers-recommended-links

    Method 3: Adjust the brightness and contrast of your monitor

    http://Windows.Microsoft.com/en-us/Windows7/adjust-your-monitors-brightness-and-contrast

    Reference:--

    Calibrate your screen

    http://Windows.Microsoft.com/en-us/Windows7/calibrate-your-display

    It will be useful. For any other corresponding Windows help, do not hesitate to contact us and we will be happy to help you.

    Kind regards!

  • What trigger should write when changing the focus to the record

    Hi all

    In oracle form 6i, I want to trigger an event when changing emphasis of a record to which record in the data block, what trigger should I write the code?

    Thank you and best regards

    Hello

    I think that you can use

    When_new_record_instance trigger to the block level

  • problem with trigger to update column

    I am creating a trigger when I INSERTS a record into the CHART table, it will also insert the record in the MASTER_TAB table as well. I can't make the statement to UPDATE the trigger.

    To do so, the relaxation, I have currently below.

    But what I am also eager to make, only to do an UPDATE if the 'REMARKS' column changes.

    So, something like:

    If the update and: NEW.COMMENTS! =: OLD.COMMENTS THEN
    do not include a record
    create or replace TRIGGER "TABLE_BIU"
    BEFORE
    INSERT OR UPDATE ON "CHART"
    FOR EACH ROW
    BEGIN
    INSERT INTO MASTER_TAB
    (
    CASE_NUMBER,
    COMMENTS
    )
    VALUES
    (
    :NEW.CASE_NUMBER,
    :NEW.COMMENTS
    );
    END;
    Thank you
    Deanna
    create or replace TRIGGER TABLE_BIU
    BEFORE
    INSERT OR UPDATE ON CHART
    FOR EACH ROW
    BEGIN
    IF INSERTING OR NOT NVL(:OLD.COMMENTS,:NEW.COMMENTS || 'X') = NVL(:NEW.COMMENTS,:OLD.COMMENTS || 'X')
    THEN
    INSERT INTO MASTER_TAB
    (
    CASE_NUMBER,
    COMMENTS
    )
    VALUES
    (
    :NEW.CASE_NUMBER,
    :NEW.COMMENTS
    );
    END IF;
    END;
    

    SY.

  • Trigger when only eno column change!

    Hello

    I have column A, B, C.
    I wonder if create a trigger that is fired when ONLY column b is changed?
    In this release I want to insert this old record of column B in another table.
    What would be the best solution for my problem?


    Kind regards
    Igor

    IgorKSCon wrote:
    When the ONLY column b is changed?

    If you want to call the trigger code only when the value of the column is changed then... you can also do like

    CREATE OR REPLACE TRIGGER trg_name AFTER
       UPDATE OF col1 ON testing FOR EACH row
       WHEN (new.col1 != old.col1) --check this line
    BEGIN
        -- your trigger body here
        NULL;
    END;
    
  • Trigger that avoids "is changing, function of triggering/can not see ' error

    Version Oracle 11.2.0.2

    I have a problem where I try to avoid duplicates in a table using a trigger.  Data looks like:

    EQUIP LO ACCT

    ---------- -- ----

    1000000000 0

    1000000001 0

    1000000002 0

    1000000003 0

    1000000004 0

    Equipment = equipment identifier

    Location = location number

    Acct = account associated with the equipment

    I need avoid the same account to have 2 pieces of equipment are allocated to the same location.

    for example

    EQUIP LO ACCT

    ---------- -- ----

    1000000000 1 1234

    1000000001 1 1234

    1000000002 0

    1000000003 0

    1000000004 0

    I can't create a unique index for this table that when there is no assigned equipment (first example) I couldn't have uniqueness through the location and number.  So, I wrote the following:

    CREATE or REPLACE TRIGGER TEST_TRG before update of test WE acct

    Old SEO AS OLD AS new NEW

    for EACH LINE

    DECLARE

    v_chk number: = 0;

    BEGIN

    Select count (*) in the test v_chk where acct =:new.acct and rental =:new.location;

    IF v_chk > 0 then raise_application_error ("-20001, ' multiple devices at the same location not allowed");

    END IF;

    END;

    /

    .. but of course that I'm shot in the table that is being updated, I get the error of mutation:

    setting a day of test set acct = "1234", location = '1' where equip = '1000000001'

    *

    ERROR on line 1:

    ORA-04091: table xxx. TEST is changing, function of triggering/can not see

    ORA-06512: in "xxx. TEST_TRG', line 4

    ORA-04088: error during execution of trigger ' xxx. TEST_TRG'

    I tried this split into two pieces where a trigger calls another procedure to perform the check and write error, but results were inconsistent and end-user demand does not pick up the error for a reason - it seems to process the transaction very well even if the update was not made at the table level.

    Are there other ways in addition to a trigger to achieve?

    Thank you!

    Adam

    Monty77 wrote:

    ... I can't do this, acct is not a null value, it is ' '.  Right or wrong it is not editable as integrated in application logic.

    Thank you!

    Adam

    Then also consider this value in your index of function according to:

    create table test

    (

    equip the varchar2 (10),

    location varchar2 (2),

    ACCT varchar2 (4)

    );

    CREATE a UNIQUE INDEX TestLocationAcct_UK ON Test

    (case when the ACCT is not null ACCT AND! =' ' then location |) « ; » || end of the ACCT);

    Insert test values ('1000000000 ', ' 0',' ');

    Insert test values ('1000000001 ', ' 0',' ');

    Insert test values ('1000000002 ', ' 0',' ');

    Insert test values ('1000000003 ', ' 0',' ');

    Insert test values ('1000000004 ', ' 0',' ');

    Update test set acct = "1234", location = '1' where equip is '1000000000';.

    Update test set acct = "1234", location = '1' where equip is '1000000001';.

    Error on line 1

    ORA-00001: unique constraint (SYSADM. TESTLOCATIONACCT_UK) violated

    Kind regards.

    Al

    Name of the index has changed to testlocationacct

  • My microphone levels uncontrollable change

    In the options of the control panel my mic rate keep is changed to random values (33 for a reason, usually), I "Allow applications to take control" unchecked & tried everything I can find online - nothing does. No matter what I try to change the mic levels!

    Hello Ed,

    Thank you for visiting Microsoft Community.

    According to the description, I understand that you have a problem with in the Control Panel options, the level of the microphone keeps have changed on random values (usually 33) in the computer.

    Of course, I understand the inconvenience caused and will try my best to help you.

    I appreciate all your efforts really to try to solve this problem.

    This issue may have caused due to card drivers his corrupt or incorrect the sound settings in the computer.

    I would suggest trying the following methods and check if it helps.

    Method 1:

    I suggest to refer to the article below and check if that helps.

    Troubleshoot audio recording

    http://Windows.Microsoft.com/en-us/Windows-Vista/troubleshoot-audio-recording-problems

    Note: The steps described in the article above also applies to Windows 7.

    If the problem persists, follow method 2

    Method 2:

    I would suggest trying the following steps and check if that helps.

    1. Download and reinstall the latest version of the driver for your sound card.

    2. If you have third-party phone such as Skype software installed on the computer, to temporally please uninstall the program such that it could block the volume level.

    3. I wonder if you have changed the volume level of the microphone in the operating system tray bar or in some applications. Please follow the steps below.

    • Click Start, click Control Panel
    • Double-click its icon, and then select general.
    • Select your audio device, and then click Properties,
    • Select the levels tab and adjust the Microphone level.
    • Then go to Advanced tag and delete "requests to authorize to take exclusive control of this device" exclusive mode.
    • Restart the computer and test the issue.

    If the problem persists, follow method 3

    Method 3:

    I suggest to refer to the article below and check if that helps.

    Automatically diagnose and fix problems of Windows audio

    https://support.Microsoft.com/en-us/mats/audiorecording/en-us?WA=wsignin1.0

    For reference:

    Please refer to the article below and check if it helps.

    Tips for solving common audio problems

    http://Windows.Microsoft.com/en-us/Windows/tips-fixing-common-sound-problems#tips-fixing-common-sound-problems=Windows-7

    I hope this information is useful.

    Please let us know if you need more help, we will be happy to help you.

    Thank you.

  • From dynamic column change for quick selection of values.

    Hello

    Requirement is based on the selection of value FAST I need to change the column values as like: "QTD_MONTH"


    for example. If the prompt value is February then the column value must be "QTD_February"

    This QTD_February is must be dynamic based on the quick selection.

    Thank you

    A Penning.

    Hello

    Instead of making the quick selection. Build separate column in the report. According to the requirement.

    Try the following formula,

    for example,.

    FILTER ("measue' to the HELP of CAST (SUBSTRING("TIME_Dimension"FROM 2 FOR 2) AS INTEGER) IN (@{wk} {26}))

    Thank you.

  • Create a view with a column change journal

    Hello

    I have the following table:

    create table test1)

    number of site_number

    date of change_date,

    number of area_ha);

    insert into test1 values (1, TO_DATE('1/1/2007','DD/MM/RRRR'), 20);

    insert into test1 values (1, TO_DATE('1/1/2008','DD/MM/RRRR'), 30);

    insert into test1 values (1, TO_DATE('1/1/2009','DD/MM/RRRR'), 25);

    insert into test1 values (2, TO_DATE('1/1/2007','DD/MM/RRRR'), 50);

    insert into test1 values (2, TO_DATE('1/1/2008','DD/MM/RRRR'), 60);

    insert into test1 values (2, TO_DATE('1/1/2009','DD/MM/RRRR'), 60);

    insert into test1 values (3, TO_DATE('1/1/2007','DD/MM/RRRR'), 20);

    insert into test1 values (3, TO_DATE('1/1/2008','DD/MM/RRRR'), 25);

    insert into test1 values (3, TO_DATE('1/1/2009','DD/MM/RRRR'), 30);

    What I want to do is to have a view based on the table above which includes a column of change (change_log below) based on the anterior surface (area_ha) for each specific site_number. For example in the first line site_number 1 has increased the area of 20 hectares on the 01/01/2007 to 30 hectares on the next change_date for this site that 01/01/2008. How this could be done?

    SITE_NUMBER CHANGE_DATE AREA_HA CHANGE_LOG
    101/01/200720NO CHANGE
    101/01/200830ADDED SPACE
    101/01/200925DELETED DOMAIN
    201/01/200750NO CHANGE
    201/01/200860ADDED SPACE
    201/01/200960NO CHANGE
    301/01/200720NO CHANGE
    301/01/200825ADDED SPACE
    301/01/200930ADDED SPACE

    I am using oracle 11g R2

    Select site_number,

    change_date,

    area_ha,

    sign of case (area_ha - lag(area_ha,1,area_ha) over (partition by order of change_date site_number))

    When 1 "AREA ADDED.

    When-1 then "ZONE DELETED."

    Another 'NO CHANGE'

    end change_log

    of test1

    order of site_number,

    change_date

    /

    SITE_NUMBER CHANGE_DA AREA_HA CHANGE_LOG
    ----------- --------- ---------- ------------
    1 1 JANUARY 07 20 NO CHANGE
    1 1 JANUARY 08-30 ADDED SPACE
    1 1 JANUARY 09 25 DELETED AREA
    2 1 JANUARY 07 50 NO. CHANGE
    2 1 JANUARY 08 60 ADDED SECTOR
    2 1 JANUARY 09 60 NO. CHANGE
    3 1ST JANUARY 07 20 NO. CHANGE
    3 AREA 1 JANUARY 08 25 ADDED
    3 1ST JANUARY 09 30 ADDED AREA

    9 selected lines.

    SQL >

    SY.

  • ADF: Partial trigger in one column of a table

    Hello people!
    I have a master - form detailed with departments - employees (HR diagram).
    In the VO of departments, I have a column transitional 'TotalSalary"calculation of the amount of the salary of all employees by the Department. I use the expression Employees.sum ("(salary is nothing)? 0: salary ").

    In the column .jspx Salary is AutoSumitted and partial target runs 'TotalSalary' salary.
    The result is fine, but the issue I'm having here is how NOT having all the Department table refreshed with every single change in detail, but only the TotalSalary column.

    Suspicion. I dragged once more the transitional column outside the table, and I noticed that the outfield is updated immediately, but the field within the table NO (because the table does not update).

    Could you please provide any help!

    Thank you very much!

    I had a similar problem. The only way is to update the table. The partial relaxation for a single column in a table works only if the trigger is also a column to the table.

  • Following level attribute what CPSA for item purchased

    Hi all

    We have an article purchased for the attribute - 'fixed multiplier of batch' is defined at the level of the element as 32 to the level of ASL - fixed multiplier attribute is null or different,

    Could you please help me to know what level attribute CPSA will all follow by creating planned order, item or ASL level

    Concerning

    Hi Nilesh,

    It should consider the FSA first, then attributes of the organization.

    Thank you
    Abhishek Sharma
    Please indicate the position appropriate or useful, if the answer

  • ODI deletes records instead of to update when a column changes

    I use a sequence of database as a primary key and have a unique key of the source data that are specified as the key to update.  Whenever I have change a column that is not part of the key (IE, I had an incorrect value for the country in the addresses, so I changed it) ODI deleted the record and inserts a new.  I can tell because the primary key is changing.  I then run all other interfaces for the new primary key is updated.   I gather there are some flags/settings I can change and it won't happen.  Anyone knows which ones who?

    -Did you select the "Update" checkbox for the primary key field in your interface?  that is, just leave "Insert" checked.

  • "All the values in column" change in the dash prompt

    In OBIEE 11 g, how to change the dashboard prompt label everything value? I don't want to change the value in the XML file, because it will prompt value impact all the dashboard.
    This is there best method to implement this problem?

    For example:
    In prompt dashboard-> edit-> options-> check ' include "All values in the column" in the list ", so I can display value"(toutes les valeurs de colonne) ' in the command prompt. " Customers want to change this value, such as 'all values '. Is this possible? Thank you.

    Hello

    Can do this by using Union All is prompt, SQL and variable presentation in the report.

    Reference: http://www.varanasisaichand.com/2010/01/editing-all-choices-in-dashboard.html

    Kind regards
    Srikanth

  • Form fields values level how chang

    Hi...........

    I want to change the values of the fields

    Here the name of the field-> mtl_eam_asset_attribute_values Depr_method (table name)

    Values-> DB, SLN (methods)

    I want to change DB to "Depreciation_method", another a SLN to 'Method of the Stright line' at the form level how
    Please give me a solution.
    Forms 10g


    Concerning
    Maha

    Hello
    I think that you posted the same question in another thread. Its best to maintain a single thread for the same topic.
    you have block db?
    If yes then you have two options
    1 item in the list as suggested earlier.
    2 control point. While in the post and when-validate-point of the iem, you can assign the corresponding description.
    If your block is not a db block, then you can use decode function when filling the data in blocks.

Maybe you are looking for