暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

Oracle 从plsql中的clob生成文件

askTom 2018-03-23
372

问题描述

嗨,汤姆。
archivos的统一编码。Aplicaci ó n接口,pero cuando se trata un set de datos muy grande la escritura del archivo falla,dando un error ORA-29285

我的pregunta como puedo controlar esa falla y manejar el tama ñ o de la linea que trato de escribir sin afectar el rendimiento del pkg。

procedure clobTofile (p_clob clob, p_directory varchar2 := 'DIR_CSV',
                       p_filename varchar2 := 'file'||userenv('SESSIONID')||to_char(systimestamp,'ddmmyyyyhh24miss')||'.csv')
  IS
    t_clob clob := p_clob;
    t_fh utl_file.file_type;
    amount pls_integer := 32767;
    offset integer := 1;
    l_leng    pls_integer := 32700;
    l_fileleng number := dbms_lob.getlength(p_clob);
    lc_buffer varchar2(32767);
    lberr_29285 exception;
    pragma EXCEPTION_INIT (lberr_29285, -29285);
  begin
    t_fh := utl_file.fopen( p_directory, p_filename, 'w');
    begin
      if ( dbms_lob.isopen(t_clob) != 1 )
      then
        dbms_lob.open(t_clob, 0);
      end if;
      --
/*
  intente controlar el maximo del campo char logre romper en segmentos tomando el string 32700 como maximo,
  sin embargo cuando recibo una linea o segmento que llega a medir 3213b pero no la longitud maxima controlada
  falla la escritura.
*/
      case when l_fileleng >= l_leng
           then
           --
           loop
               amount := instr(dbms_lob.substr( t_clob, l_leng, offset), l_endofline, -1);
               exit when nvl(amount,0) = 0;
               lc_buffer := dbms_lob.substr( t_clob, amount, offset);
               utl_file.put_line( t_fh, lc_buffer);
               offset := offset + amount;
           end loop;
      else
        utl_file.put_line( t_fh, dbms_lob.substr( t_clob, l_fileleng, offset));        
      end case;
      if ( dbms_lob.isopen(t_clob) = 1 ) then
           dbms_lob.close(t_clob);
      end if;
    exception
      when lberr_29285 then
        dbms_output.put_line('Error :Error de escritura en el archivo archivo destino');
      raise;
      when others then
         dbms_output.put_line('Error : '||sqlerrm);
         raise;
    end printout;
    utl_file.fclose( t_fh );
  end;
复制

专家解答

我希望我理解你的问题-我用谷歌翻译。

默认情况下,UTL_FILE只允许很小的线宽。

更改

utl_file.fopen (目录,文件名,'w');



utl_file.fopen( p_directory,p_filename,'w',32767);

到allow a line 到go up 到32k in size.
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论