Solved

Oracle: Trigger to capture table updates

Posted on 2006-06-22
2
388 Views
Last Modified: 2008-01-09
I'd like to write a trigger that will capture updates made to a certain column of a table, and place the old and new values into another table.

Cost_Table
Product:    Watch
Price:       200

If the price of the watch is changed to 300, a row should be inserted into Cost_Table_Updates as follows:
Product:   Watch
Old_Price: 200
New_Price: 300

Thanks!
0
Comment
Question by:TotalEnergy
2 Comments
 
LVL 25

Accepted Solution

by:
jrb1 earned 500 total points
ID: 16963748
create or replace trigger
   Cost_Table_Updates
after update on cost_table
for each row

BEGIN
   IF UPDATING ('PRICE') THEN
      INSERT INTO Cost_Table_Updates (product, old_price, new_price)
         VALUES (:new.product, :old.price, :new.price);
   END IF;
END;
/
0
 
LVL 3

Expert Comment

by:hardikbeit
ID: 16966514
Trigger:

Create or Replace Trigger Update_Cost_watch
AFTER update ON cost_table --Before or after as per your requirement
REFERENCING NEW AS NEW OLD AS OLD
FOR EACH ROW

BEGIN
  IF UPDATING THEN
    IF :NEW.PRICE=300 THEN
        INSERT INTO Cost_Table_Updates(product, old_price, new_price)
        VALUES (:new.product_id, :Old.Price,:NEW.Price);
    END IF;
  END IF;
END;

This helps you.

Regards, Hardik
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
syadmin MSSQL 2 71
Input Data Using a unique ID from another sheet in Excel 3 52
best datatype for oracle table email creation 8 56
SQL Query assistance 16 36
Shadow IT is coming out of the shadows as more businesses are choosing cloud-based applications. It is now a multi-cloud world for most organizations. Simultaneously, most businesses have yet to consolidate with one cloud provider or define an offic…
Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question