CREATE OR REPLACE FUNCTION HAL_NUMERO
(P_NUMERO      IN NOTAFISCAL.NRNOTAFISC%TYPE) RETURN VARCHAR
IS
   V_NUMEROALT  VARCHAR2(20);
BEGIN
   IF LENGTH(TRUNC(P_NUMERO)) < 6 THEN
      V_NUMEROALT := LPAD(TRUNC(P_NUMERO), '6','0');
   ELSE
      V_NUMEROALT := TRUNC(P_NUMERO);
   END IF;

   RETURN(V_NUMEROALT);
END;
/

-- VERSAO --
BEGIN ATUVEROBJ('HAL_NUMERO','5.60.XXX'); END;
/