CREATE OR REPLACE FUNCTION GREATESTNULL(
   P_VALOR1     IN NUMBER DEFAULT NULL,
   P_VALOR2     IN NUMBER DEFAULT NULL,
   P_VALOR3     IN NUMBER DEFAULT NULL) RETURN NUMBER IS

BEGIN
   IF (P_VALOR1 IS NULL) AND
      (P_VALOR2 IS NULL) AND
      (P_VALOR3 IS NULL) THEN
      RETURN(NULL);
   ELSE
      RETURN(GREATEST(NVL(P_VALOR1,0),NVL(P_VALOR2,0),NVL(P_VALOR3,0)));
   END IF;
END;
/