Oracle trigger inserting or updating contact dating online
For Example: The price of a product changes constantly.
TRG_BEFORE_EMP_UPDATE' --Creating person_records table. CREATE TABLE person_records ( PERSON_ID number(10) primary key, FIRST_NAME varchar2(50), LAST_NAME varchar2(50), HIRE_DATE date, UPDATED_BY varchar2(20), UPDATED_DATE date ); CREATE OR REPLACE TRIGGER trg_before_person_update BEFORE UPDATE on person_records FOR EACH ROW DECLARE username varchar2(20); BEGIN SELECT USER INTO username FROM dual; -- Setting updated_by and updated_Date values.
This is because compound trigger in oracle 11g has a declarative section where one can declare variable to be used within trigger.
This common state is established at the start of triggering statement and is destroyed after completion of trigger (regardless of trigger being in error or not).
If same had to be done without compound-trigger, it might have been required to share data using packages.
The compound trigger is useful when you want to accumulate facts that characterize the “for each row” changes and then act on them as a body at “after statement” time.