CREATE OR REPLACE TRIGGER LOG_VND_TABEPRECGER
AFTER DELETE OR INSERT OR UPDATE
ON TABEPRECGER FOR EACH ROW
DECLARE
  V_DSREMOTEADDR VARCHAR2(15);
  V_DSREMOTEHOST VARCHAR2(15);
  V_DSSERVERRDM  VARCHAR2(20);
  V_DSSERVMETHOD VARCHAR2(30);
  V_DSREMOTEOPER VARCHAR2(12);
  V_DESC         VARCHAR2(500);
  V_ITPESQ       VARCHAR2(40);
  V_NMOPERADOR   VARCHAR2(40);
  V_IDTIPOOPER   VARCHAR2(1);
BEGIN
/* IDTIPOOPER - '1' - Inclusao, '2' - Alteracao, '3' - Exclusao*/
   V_DESC       := '';
   V_ITPESQ     := '';
   V_NMOPERADOR := '';
   V_IDTIPOOPER := '';
   NMUSUARIO(V_NMOPERADOR);
   WEBTUNNING(V_DSREMOTEADDR,
              V_DSREMOTEHOST,
              V_DSSERVERRDM,
              V_DSSERVMETHOD,
              V_DSREMOTEOPER);
   IF UPDATING THEN
		IF NVL(:NEW.CDTABEPREC ,'NULL') <> NVL(:OLD.CDTABEPREC ,'NULL') THEN
            V_DESC := NVL(V_DESC, '') || ' ' || 'Cd da Tabela de Preco ' || ' ' || NVL(:NEW.CDTABEPREC,'');
		END IF;
		IF NVL(:NEW.NMTABEPREC ,'NULL') <> NVL(:OLD.NMTABEPREC ,'NULL') THEN
            V_DESC := NVL(V_DESC, '') || ' ' || 'Nm da Tabela de Preco ' || ' ' || NVL(:NEW.NMTABEPREC,'' );
		END IF;
		IF NVL(:NEW.DTULTATU,TO_DATE('01/01/0001','DD/MM/YYYY'))  <> NVL(:OLD.DTULTATU,TO_DATE('01/01/0001','DD/MM/YYYY'))  THEN
            V_DESC := NVL(V_DESC, '') || ' ' || 'Dt Ult Atu do Preco ' || ' ' || NVL(:NEW.DTULTATU,'');
		END IF;
      V_ITPESQ := :NEW.CDTABEPREC;
      V_IDTIPOOPER := '2';
   ELSE
      IF INSERTING THEN
      V_DESC   := 'Cd da Tabela de Preco ' || '' || NVL(:NEW.CDTABEPREC,''  )     || ' ' ||
                  'Nm da Tabela de Preco ' || '' || NVL(:NEW.NMTABEPREC,'' )   	  || ' ' || 
                  'Dt Ult Atu do Preco '   || '' || NVL(:NEW.DTULTATU,'');
      V_ITPESQ := :NEW.CDTABEPREC;
         V_IDTIPOOPER := '1';
      ELSE
         IF DELETING THEN
      V_DESC   := 'Cd da Tabela de Preco ' || '' || NVL(:OLD.CDTABEPREC,''  )     || ' ' ||
                  'Nm da Tabela de Preco ' || '' || NVL(:OLD.NMTABEPREC,'' )   	  || ' ' || 
                  'Dt Ult Atu do Preco '   || '' || NVL(:OLD.DTULTATU,'');
      V_ITPESQ := :OLD.CDTABEPREC;
            V_IDTIPOOPER := '3';
         END IF;
      END IF;
   END IF;
   V_DESC := SUBSTR(V_DESC, 1, 300);
   INSERT INTO LOGOPERAVND
      (NMTABELAVND,
       DTOPERACAOVND,
       NMRESPOPERVND,
       IDTIPOOPERVND,
       DSOPERACAOVND,
       CDPESQITEMVND,
       DSRDMUSUOPERVND,
       DSENDUSUOPERVND,
       DSNMUSUOPERVND,
       DSMETUSUOPERVND,
       CDORESPOPERVND,
       CDFILLOGOPERVND)
   VALUES
      ('TABEPRECGER',
       SYSDATE,
       NVL(V_NMOPERADOR,' '),
       V_IDTIPOOPER,
       NVL(V_DESC,' '),
       V_ITPESQ,
       V_DSSERVERRDM,
       V_DSREMOTEADDR,
       V_DSREMOTEHOST,
       V_DSSERVMETHOD,
       V_DSREMOTEOPER,
       NULL);
END;
/