CREATE OR REPLACE FUNCTION FORMATITTRABMASK (P_CDARVITTRAB IN VARCHAR2) RETURN VARCHAR2
IS
   V_FORMATMASK VARCHAR2(50);
   V_CDPICTITTRAB PARAMGERAL.CDPICTITTRAB%TYPE;
   V_CDARVITTRAB  ITEMTRAB.CDARVITTRAB%TYPE;
   V_MASKLENGTH FLOAT;
BEGIN
   SELECT CDPICTITTRAB, LENGTH(CDPICTITTRAB)
   INTO V_CDPICTITTRAB, V_MASKLENGTH
   FROM PARAMGERAL;

   V_FORMATMASK := '';
   V_CDARVITTRAB := P_CDARVITTRAB;

   FOR V_LOOP IN 1..V_MASKLENGTH
   LOOP
      IF(SUBSTR(V_CDPICTITTRAB, V_LOOP, 1) = '.') THEN
         V_FORMATMASK := V_FORMATMASK||'.';
         V_CDARVITTRAB  := V_FORMATMASK||SUBSTR(V_CDARVITTRAB, V_LOOP, V_MASKLENGTH);
      ELSE
         V_FORMATMASK := V_FORMATMASK||SUBSTR(V_CDARVITTRAB, 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;
/