CREATE OR REPLACE FUNCTION BUSCA_ALUGUEL_CNC(P_NRADQUIRENTE IN NUMBER,
                                             P_NRESTABELEC IN NUMBER,
                                             P_VRALUGUEL IN NUMBER) RETURN VARCHAR
AS
   V_EXISTE VARCHAR2(01);
BEGIN
   V_EXISTE := 'N';
   BEGIN
      SELECT 'S'
        INTO V_EXISTE
        FROM TECNOLOGIAADQ
       WHERE NRESTABELEC = P_NRESTABELEC
         AND NRADQUIRENTE = P_NRADQUIRENTE
         AND VRALUGUEL = P_VRALUGUEL;
   EXCEPTION
      WHEN NO_DATA_FOUND THEN
         V_EXISTE := 'N';
   END;

   IF V_EXISTE = 'N' THEN
      BEGIN
         SELECT 'S'
           INTO V_EXISTE
           FROM TECNOLOGIAADQ
          WHERE NRADQUIRENTE = P_NRADQUIRENTE
            AND VRALUGUEL = P_VRALUGUEL;
      EXCEPTION
         WHEN NO_DATA_FOUND THEN
            V_EXISTE := 'N';
      END;
   END IF;

   RETURN V_EXISTE;
END;
/

-- VERSAO --
BEGIN ATUVEROBJ('BUSCA_ALUGUEL_CNC','6.10.000'); END;
/
