Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Oracle: Trigger to capture table updates

Posted on 2006-06-22
2
Medium Priority
?
393 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 25

Accepted Solution

by:
jrb1 earned 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Lotus Notes has been used since a very long time as an e-mail client and is very popular because of it's unmatched security. In this article we are going to learn about  RRV Bucket corruption and understand various methods to Fix "RRV Bucket Corrupt…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

610 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