Pular para o conteúdo
Visualizando 4 posts - 1 até 4 (de 4 do total)
  • Autor
    Posts
  • #105722
    Avatar de David CorreaDavid Correa
    Participante

      Pessoal, boa tarde!

      Estou quebrando a cabeça aqui no trabalho a alguns dias e ainda não cheguei em uma solução. Então gostaria da ajuda de vc! rs

      Estou precisando gravar um arquivo txt via utl_file. O arquivo é gerado sem problemas, porém, no final do arquivo ele acrescenta uma quebra de linha depois da última linha do arquivo. Como esta no arquivo de exemplo em anexo.

      Preciso que o arquivo termine na última linha do registro que estou gravando, sem a quebra no final do arquivo (a linha 6 do exemplo). Tem como fazer isso?

      Estou usando o scrip abaixo:

      Begin
      Declare
      filePath Varchar2(400);
      Cursor Cs_Campanha Is
      Select ‘R06_CL7496_BR_IN_IncomingMonetary_MARKTBI_001_’||TO_CHAR(SYSDATE,’DDMMYYHH24MISS’) cdMailing, sysdate, TO_CHAR(SYSDATE,’DDMMYYHH24MISS’) From Dual;
      r_Campanha cs_Campanha%Rowtype;
      –vrAbordagem Integer;
      Texto Utl_File.file_type;
      Begin
      For r_Campanha In cs_Campanha Loop
      filePath := r_Campanha.cdMailing || ‘.TXT’;
      Texto := utl_file.fopen(‘ETLDBM’, filePath, ‘W’);
      Declare
      Cursor cs_Mala Is

      select Registro
      from (
      –Header de Arquivo
      select 1 Ordem,
      LPAD(‘TFH’,003,’0′) || — Record ID
      LPAD(To_Char(Sysdate,’YYYYMMDD’),008,’0′) || — File Creation Date
      RPAD(‘Manual’,050,’ ‘) || — File Source
      LPAD(‘ ‘,339,’ ‘) — Filler

      Registro
      from dual
      union
      –Detail
      Select 2 Ordem,
      LPAD(‘TDC’,003,’ ‘) || — Record ID
      RPAD(‘SFEE’,005,’ ‘) || — Transaction Original Message Type
      RPAD(‘mntf’,004,’ ‘) || — Transaction Reason Code
      LPAD(‘2′,001,’0’) || — Original/Reversal Indicator
      LPAD(‘0′,001,’0’) || — Reverse Billed Transactions
      LPAD(‘2′,001,’0’) || — Transaction Message Code
      LPAD(‘0′,001,’0′) || — Transaction Sign
      LPAD(W.CTA_NUMBERX,025,’ ‘) || — Card Number/Account/ Number Statement Reference
      LPAD(‘3′,001,’0’) || — Card/Account/Statement Reference
      LPAD(‘986′,003,’0′) || — Transaction Currency
      LPAD(TO_CHAR(W.VL_POSTAGEM*1000),016,’0′) || — Transaction Amount
      LPAD(TO_CHAR(SYSDATE,’YYYYMMDD’),008,’0′) || — Transaction Date
      LPAD(To_Char(Sysdate,’YYYYMMDD’),008,’0′) || — Transaction Value Date
      RPAD(‘Anuidade Diferenciada ‘ || W.Parcela || ‘/12′,250,’ ‘) || — Transaction Description
      LPAD(‘ ‘,073,’ ‘) — Filler
      Registro
      From David_Correa.Tb_Cb_Piloto_Post W
      Where Trunc(W.Dt_Postagem, ‘dd’) = Trunc(Sysdate, ‘dd’)

      union
      –Trailler de Arquivo
      select 3 Ordem,
      LPAD(‘TFT’,003,’ ‘) || — Record ID
      LPAD(Count(*),016,’0′) || — Number of Records
      LPAD(TO_CHAR(SUM(W.VL_POSTAGEM*1000)),016,’0’) || — Hash Total Amount
      LPAD(‘ ‘,365,’ ‘) — Filler

      Registro
      FROM David_Correa.Tb_Cb_Piloto_Post W
      Where Trunc(W.Dt_Postagem, ‘dd’) = Trunc(Sysdate, ‘dd’)

      ) order by ordem asc
      ;

      R Cs_Mala%Rowtype;
      Begin
      For R In Cs_Mala Loop
      Utl_File.Put_Line (Texto, R.Registro);
      Commit;
      End Loop;
      End;
      Utl_File.Fflush(Texto);
      Utl_File.fclose(Texto);
      Commit;
      End Loop;
      Commit;
      End;
      end;

      Obrigado!!

      Attachments:
      #105723
      Avatar de rmanrman
      Participante

        @david_correa

        Na última linha a ser gravada no arquivo você deve utilizar UTL_FILE.PUT ao invés de UTL_FILE.PUT_LINE.

        #105724
        Avatar de David CorreaDavid Correa
        Participante

          Bom dia!

          rman,

          Tentei fazer isso, substituir o put_line por put mas dá o erro abaixo.
          Relatório de erro:
          ORA-29285: erro de gravação em arquivo
          ORA-06512: em “SYS.UTL_FILE”, line 183
          ORA-06512: em “SYS.UTL_FILE”, line 1169
          ORA-06512: em line 72
          29285. 00000 – “file write error”
          *Cause: Failed to write to, flush, or close a file.
          *Action: Verify that the file exists, that it is accessible, and that
          it is open in write or append mode.

          Será que tem que alterar mais alguma coisa?

          Obrigado!

          #105725
          Avatar de rmanrman
          Participante

            @david_correa

            Voltei com o PUT_LINE e teste, creio que esse erro não está relacionado com o PUT. É erro de escrita, talvez permissões no arquivo, ou espaço em disco.

          Visualizando 4 posts - 1 até 4 (de 4 do total)
          • Você deve fazer login para responder a este tópico.
          plugins premium WordPress