CREATE OR REPLACE FUNCTION GIA_PE_ANUAL_9(
   P_CONTREG         IN NUMBER,
   P_NRSEQARQMAG     IN ARQMAGNETICO.NRSEQARQMAG%TYPE) RETURN NUMBER
AS
   V_CONTREG  NUMBER;
BEGIN
   V_CONTREG := NVL(P_CONTREG,0);

   FOR C_REG_9 IN (SELECT LPAD(V_CONTREG,6,'0')                               ||
                          '9'                                                 ||
                          '000001'                                            ||
                          LPAD(P_CONTREG,6,'0') AS DSARQMAG
                     FROM DUAL) LOOP

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

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

  RETURN V_CONTREG;
END;
/

-- VERSAO --
BEGIN ATUVEROBJ('GIA_PE_ANUAL_9','6.39.005'); END;
/
