CREATE OR REPLACE FUNCTION GIA_PE_ANUAL_0(
   P_VERSAO       IN VARCHAR2,
   P_RELEASE      IN VARCHAR2,
   P_NRSEQARQMAG  IN ARQMAGNETICO.NRSEQARQMAG%TYPE) RETURN NUMBER
AS
   V_CONTREG  NUMBER;
BEGIN

  V_CONTREG := NVL(V_CONTREG,0) + 1;

  FOR C_REG_0 IN (SELECT LPAD(V_CONTREG,6,'0')       ||
                         '0'                         ||
                         'GIA  '                     ||
                         P_VERSAO                    ||
                         P_RELEASE                   ||
                         ' '                         ||
                         TO_CHAR(SYSDATE,'YYYYMMDD') ||
                         TO_CHAR(SYSDATE,'HH24:MI:SS') AS DSARQMAG
                    FROM DUAL) LOOP

     INSERT INTO ARQMAGNETICO
        (NRORDREGARQ, DSREGARQMAG, NRSEQARQMAG)
     VALUES
        (LPAD(RTRIM(V_CONTREG), 10, '0'), C_REG_0.DSARQMAG, P_NRSEQARQMAG);

      V_CONTREG := NVL(V_CONTREG,0) + 1;
  END LOOP;

  RETURN V_CONTREG;
END;
/