CREATE OR REPLACE FUNCTION FORMATPRODMASK (P_CDARVPROD IN VARCHAR2) RETURN VARCHAR2
IS
  V_FORMATMASK VARCHAR2(50);
  V_CDPICTPROD VARCHAR2(50);
  V_CDARVPROD  VARCHAR2(50);
  V_MASKLENGTH FLOAT;
BEGIN
  SELECT CDPICTPROD, LENGTH(CDPICTPROD)
    INTO V_CDPICTPROD, V_MASKLENGTH
    FROM PARAMGERAL;
     
  V_CDARVPROD := P_CDARVPROD; 
  FOR V_LOOP IN 1..V_MASKLENGTH
  LOOP 
    IF(SUBSTR(V_CDPICTPROD, V_LOOP, 1) = '.') THEN
      V_FORMATMASK := V_FORMATMASK||'.';
      V_CDARVPROD  := V_FORMATMASK||SUBSTR(V_CDARVPROD, V_LOOP, V_MASKLENGTH);
    ELSE
      V_FORMATMASK := V_FORMATMASK||SUBSTR(V_CDARVPROD, V_LOOP, 1);
    END IF;
  END LOOP;
   
  WHILE SUBSTR(V_FORMATMASK, LENGTH(V_FORMATMASK), 1) = '.' 
  LOOP
    V_FORMATMASK := SUBSTR(V_FORMATMASK, 0 , LENGTH(V_FORMATMASK)-1);
  END LOOP;
  RETURN(V_FORMATMASK);
END;
/

-- VERSAO --
BEGIN ATUVEROBJ('FORMATPRODMASK','6.35.009'); END;
/
