Row level, statement level Trigger

Preview

Create two table based on query:

CREATE TABLE product
(Message varchar2(50),
 Current_Date date
);

CREATE TABLE product_log
(Message varchar2(4000),
 Current_Date date
);
  • Statement level trigger
CREATE or REPLACE TRIGGER Before_Update_Stat_product
BEFORE
UPDATE ON product
Begin
INSERT INTO product_log
Values('Before update, statement level',sysdate);
END;
/
 CREATE or REPLACE TRIGGER After_Update_Stat_product
 AFTER
 UPDATE ON product
 BEGIN
 INSERT INTO product_log
 Values('After update, statement level', sysdate);
 End;
 /
  • Row level trigger
CREATE or REPLACE TRIGGER Before_Update_Row_product
 BEFORE
 UPDATE ON product
 FOR EACH ROW
 BEGIN
 INSERT INTO product_log
 Values('Before update row level :   '||:old.message||' - - '||:new.message,sysdate);
 END;
 /
 CREATE or REPLACE TRIGGER After_Update_Row_product
 AFTER
 insert On product
 FOR EACH ROW
 BEGIN
 INSERT INTO product_log
 Values('After insert, Row level',sysdate);
 END;
 /
  • Test the trigger:
insert into product values ('ashish',sysdate);
/
update  product set message = 'Ashish Sahay' where current_date = sysdate;
/

You might Like:


comments powered by Disqus