CREATE OR REPLACE FUNCTION ARQDIGITAL_BLOCO8(
   P_CDEMPRESA    IN EMPRESA.CDEMPRESA%TYPE,
   P_NRSEQARQMAG  IN ARQMAGNETICO.NRSEQARQMAG%TYPE) RETURN NUMBER
AS
   V_REGTOT8     NUMBER;
BEGIN

   /* ABERTURA DO BLOCO 8 */
   INSERT INTO ARQMAGNETICO
        (NRORDREGARQ, DSREGARQMAG, NRSEQARQMAG)
      VALUES
        ('56'||LPAD(RTRIM('1'), 8, '0'), '|8001'||'|'||
                                         '1'   ||'|'||
                                         'DF'  ||'|', P_NRSEQARQMAG);
   V_REGTOT8 := NVL(V_REGTOT8,0) + 1;

   /* ENCERRAMENTO DO BLOCO 8 */
   V_REGTOT8 := NVL(V_REGTOT8,0) + 1;
   INSERT INTO ARQMAGNETICO
        (NRORDREGARQ, DSREGARQMAG, NRSEQARQMAG)
      VALUES
        ('57'||LPAD(RTRIM('1'), 8, '0'), '|8990'||'|'||
                                         '2'   ||'|'  , P_NRSEQARQMAG);

   RETURN(V_REGTOT8);
END;
/

