CREATE OR REPLACE TRIGGER CINEMA.TRG_ORA_VENDITE
BEFORE INSERT OR UPDATE
OF IDVEND
  ,IDBIGLIETTO
  ,TIPO
  ,NUM_BIGL
  ,IDCASSA
  ,VALUTA
  ,IDCALEND
ON CINEMA.VENDITE 
REFERENCING NEW AS NEW OLD AS OLD
FOR EACH ROW
DECLARE 
    iDate DATE; 
BEGIN 
    IF INSERTING THEN 
        :new.DATA_AGG := SYSDATE; 
    END IF;

    IF UPDATING THEN 
	   
	   IF :old.DATA_AGG IS NULL THEN 
		  :new.DATA_AGG:= SYSDATE; 
	   END IF;

	   IF :old.NUM_BIGL = 0 THEN 
		  :new.DATA_AGG:= SYSDATE; 
	   END IF;	   
	   
    END IF; 

END;