create or replace TRIGGER OU_REF.TIME_TRANSFORMATION_H
BEFORE INSERT OR UPDATE OR DELETE ON OU_REF.TIME_TRANSFORMATION
REFERENCING NEW AS new OLD AS old
FOR EACH ROW
DECLARE
  v_current_date DATE := SYSDATE;
  v_future_date DATE  := TO_DATE('31/12/9999', 'DD/MM/YYYY');
BEGIN
  IF INSERTING THEN
    INSERT INTO DW_REF_MAIN.TIME_TRANSFORMATION(YEAR_START, TIME_ZONE_START, CALENDAR_DATE_START, YEAR_END, TIME_ZONE_END, CALENDAR_DATE_END)
    VALUES (:new.YEAR_START, :new.TIME_ZONE_START, :new.CALENDAR_DATE_START, :new.YEAR_END, :new.TIME_ZONE_END, :new.CALENDAR_DATE_END);
  ELSIF DELETING THEN
    DELETE FROM DW_REF_MAIN.TIME_TRANSFORMATION
    WHERE  
        1 = 1 
    AND DECODE(YEAR_START, :old.YEAR_START, 1, 0) = 1
    AND DECODE(TIME_ZONE_START, :old.TIME_ZONE_START, 1, 0) = 1
    AND DECODE(CALENDAR_DATE_START, :old.CALENDAR_DATE_START, 1, 0) = 1
    AND DECODE(YEAR_END, :old.YEAR_END, 1, 0) = 1
    AND DECODE(TIME_ZONE_END, :old.TIME_ZONE_END, 1, 0) = 1
    AND DECODE(CALENDAR_DATE_END, :old.CALENDAR_DATE_END, 1, 0) = 1
  ;
  ELSIF UPDATING THEN
    UPDATE DW_REF_MAIN.TIME_TRANSFORMATION SET
      YEAR_START = :new.YEAR_START, 
      TIME_ZONE_START = :new.TIME_ZONE_START, 
      CALENDAR_DATE_START = :new.CALENDAR_DATE_START, 
      YEAR_END = :new.YEAR_END, 
      TIME_ZONE_END = :new.TIME_ZONE_END, 
      CALENDAR_DATE_END = :new.CALENDAR_DATE_END 
    WHERE  
        1 = 1 
    AND DECODE(YEAR_START, :old.YEAR_START, 1, 0) = 1
    AND DECODE(TIME_ZONE_START, :old.TIME_ZONE_START, 1, 0) = 1
    AND DECODE(CALENDAR_DATE_START, :old.CALENDAR_DATE_START, 1, 0) = 1
    AND DECODE(YEAR_END, :old.YEAR_END, 1, 0) = 1
    AND DECODE(TIME_ZONE_END, :old.TIME_ZONE_END, 1, 0) = 1
    AND DECODE(CALENDAR_DATE_END, :old.CALENDAR_DATE_END, 1, 0) = 1
  ;
  END IF;
END;
/