CREATE OR REPLACE FUNCTION FORMATMASKCEP (P_DSCEP IN VARCHAR2) RETURN VARCHAR2 IS
   V_FORMATMASKCEP VARCHAR2(50);
BEGIN
   IF P_DSCEP IS NULL THEN 
      RETURN(NULL);
   END IF;
   
   SELECT SUBSTR(REGEXP_REPLACE(TRIM(P_DSCEP), '[^0-9A-Za-z]', '') , 1 , 5 ) ||  '-' || SUBSTR(REGEXP_REPLACE(TRIM(P_DSCEP), '[^0-9A-Za-z]', '') , 6 , LENGTH(P_DSCEP))
     INTO V_FORMATMASKCEP
     FROM DUAL;
   
   RETURN(V_FORMATMASKCEP);
END;
/