CREATE OR REPLACE TRIGGER USR_ATU_ENVIOAFFORN_SAP
BEFORE INSERT
   ON ENVIOAFFORN FOR EACH ROW
DECLARE
  V_NRINSJURFORN VARCHAR2(20);
BEGIN
   BEGIN
      SELECT NRINSJURFORN
        INTO V_NRINSJURFORN
        FROM FORNECEDOR
       WHERE CDFORNECED  = :NEW.CDFORNECED
         AND NVL(FORNECEDOR.USR_INTEGRAMESAP, 'N') = 'S';
   EXCEPTION
      WHEN NO_DATA_FOUND THEN
         V_NRINSJURFORN := NULL;
   END;
   IF V_NRINSJURFORN IS NOT NULL THEN
      :NEW.USR_IDINTEGRAMESAP  := 'S';
   END IF;
END;
/

-- VERSAO --
BEGIN ATUVEROBJ('USR_ATU_ENVIOAFFORN_SAP','6.02.XXX'); END;
/