CREATE OR REPLACE TRIGGER LOG_DADOSFORNECOMMERCE
AFTER INSERT OR UPDATE OR DELETE 
ON DADOSFORNECOMMERCE FOR EACH ROW
DECLARE
	V_CDFORNECED VARCHAR2(21);
	V_IDOPERACAO VARCHAR2(1);
	V_NMUSUARIOECO VARCHAR2(50);
	V_DSLOGINECO VARCHAR2(200);
	V_IDACESSOCOT VARCHAR2(1);
	V_IDACESSOAF VARCHAR2(1);
	V_IDACESSOCR VARCHAR2(1);
	V_IDACESSOUPLOAD VARCHAR2(1);
	V_IDADMINISTRADOR VARCHAR2(1);
	V_DSEMAILECO  VARCHAR2(250);
BEGIN
	V_IDOPERACAO := CASE WHEN INSERTING THEN 'I' WHEN UPDATING THEN 'U' ELSE 'D' END;
	
	V_CDFORNECED := NVL(:NEW.CDFORNECED, :OLD.CDFORNECED); 
	
	V_NMUSUARIOECO := NVL(:NEW.NMUSUARIOECO, :OLD.NMUSUARIOECO); 
	V_DSLOGINECO := NVL(:NEW.DSLOGINECO, :OLD.DSLOGINECO); 
	V_IDACESSOCOT := NVL(:NEW.IDACESSOCOT, :OLD.IDACESSOCOT); 
	V_IDACESSOAF := NVL(:NEW.IDACESSOAF, :OLD.IDACESSOAF); 
	V_IDACESSOCR := NVL(:NEW.IDACESSOCR, :OLD.IDACESSOCR); 
	V_IDACESSOUPLOAD := NVL(:NEW.IDACESSOUPLOAD, :OLD.IDACESSOUPLOAD); 
	V_IDADMINISTRADOR := NVL(:NEW.IDADMINISTRADOR, :OLD.IDADMINISTRADOR); 
	V_DSEMAILECO := NVL(:NEW.DSEMAILECO, :OLD.DSEMAILECO);

	INSERT INTO LOGDADOSFORNECOMMERCE
	(NRLOGDADOSFORNECOMMERCE, CDFORNECED, DTOPERACAO, IDOPERACAO,
	 NMUSUARIOECO, DSLOGINECO, IDACESSOCOT, IDACESSOAF, IDACESSOCR,
	 IDACESSOUPLOAD, IDADMINISTRADOR, DSEMAILECO)
	VALUES
	(SEQ_LOGDADOSFORNECOMMERCE.NEXTVAL, V_CDFORNECED, SYSDATE, V_IDOPERACAO,
	 V_NMUSUARIOECO, V_DSLOGINECO, V_IDACESSOCOT, V_IDACESSOAF, V_IDACESSOCR,
	 V_IDACESSOUPLOAD, V_IDADMINISTRADOR, V_DSEMAILECO);
END;
/