CREATE OR REPLACE FUNCTION UTILIZA_NMPROD_CODIFICADO(P_CDOPERADOR IN OPERADOR.CDOPERADOR%TYPE)RETURN VARCHAR2
AS
   V_IDVISUNMPRCOD   PARAMGERAL.IDVISUNMPRCOD%TYPE := 'N';
   V_CDGROPERNMNCOD  PARAMGERAL.CDGROPERNMNCOD%TYPE := '';
   V_OPGROUP         INTEGER := 0;
BEGIN
   SELECT NVL(MAX(IDVISUNMPRCOD), 'N'), NVL(MAX(CDGROPERNMNCOD), '')
     INTO V_IDVISUNMPRCOD, V_CDGROPERNMNCOD
     FROM PARAMGERAL
    WHERE CDPARGERAL = '0001';

   IF V_IDVISUNMPRCOD = 'S' THEN
      SELECT COUNT(*)
        INTO V_OPGROUP
        FROM OPERGRUPOP
       WHERE (CDOPERADOR = P_CDOPERADOR)
         AND (CDGRUPOPER = V_CDGROPERNMNCOD);

      IF V_OPGROUP > 0 THEN
         V_IDVISUNMPRCOD := 'N';
      END IF;
   END IF;
   RETURN V_IDVISUNMPRCOD;
END;
/