Oracle trigger if updating column
Burleson is trying to say as he fails to distinguish between updates to columns, updates to rows, and the entire update statement.
Now let’s create a trigger on ‘new_employee’ table so that whenever we are updating any employee record in the ‘new_employee’ table the same record also gets stored in ‘new_employee_duplicate’ table.For example: create table t1 ( id$ integer not null, charcol char default 'Y', datecol date default sysdate, strcol varchar2(30) default user, intcol integer default 12 ); insert into t1 (id$) values (1); select * from t1; ID$ C DATECOL STRCOL INTCOL ————— - ————- ——————————————— ————— 1 Y 28-MAY-04 SCOTT 12 VALUES () as valid SQL.A simple test could protect against “false updates”, and perhaps bypass the update and send an alert log message that a DML statement is doing superfluous updates.Triggers are a special PL/SQL construct similar to procedures.In Oracle, a sequence object (created by CREATE SEQUENCE statement) is used to generate IDs (auto-increment, identity values).The first only cares if the value is actually being altered.
Since Oracle 9i, you may use pseudocolumns like SYSDATE or CURRENT_TIMESTAMP in DEFAULT clauses.
We cannot create an AFTER INSERT TRIGGER on an Oracle PLSQL VIEW.
We cannot update : NEW values with AFTER INSERT TRIGGER.
overheads of roughly 5,000,000 redundant row updates per night.
Burleson’s comment might seem quite sensible – after all it shouldn’t take much CPU to work out which rows should and should not be updated, and it ought to be quite simple to skip the rows that aren’t going to change.
For this purpose we can create a PLSQL AFTER UPDATE TRIGGER as: CREATE OR REPLACE TRIGGER new_employee_trigger AFTER UPDATE ON new_employee FOR EACH ROW DECLARE v_creator_name VARCHAR2(1000); v_creation_date DATE; BEGIN --Getting the name of the current logged in User SELECT USER INTO v_creator_name FROM dual; --setting system date in v_creation_date v_creation_date := sysdate; --Inserting data the new_employee_duplicate table INSERT INTO new_employee_duplicate VALUES (:new.employee_id ,:new.employee_name ,v_creation_date ,v_creator_name); END; Here we have created a PLSQL AFTER UPDATE TRIGGER named ‘new_employee_trigger’ which will insert a record in the ‘new_employee_duplicate’ table as soon as update operation is performed on ‘new_employee’ table.