不能用UTL_FILE.PUT_LINE写出大尺寸的数据 [英] not able to write a big size data with UTL_FILE.PUT_LINE

查看:830
本文介绍了不能用UTL_FILE.PUT_LINE写出大尺寸的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个包含大量数据的xml。现在我正在尝试将生成的xml写入文件。



声明:

  prodFeed_file UTL_FILE.FILE_TYPE; 
prodFeed_file:= UTL_FILE.FOPEN('CSV_DIR','feed.xml','w',32767);

写入文件:

  UTL_FILE.PUT_LINE(prodFeed_file,l_xmltype.getClobVal); 

UTL_FILE.FCLOSE(prodFeed_file);

如果 l_xmltype.getClobVal 它是工作文件,但如果 l_xmltype.getClobVal 超过大小(差不多35 KB),则会显示错误信息:

< ORA-06502:PL / SQL:数值或值错误

解决方案

p> UTL_FILE文档


除非您在FOPEN中指定较小的大小,否则缓冲区参数的最大大小为32767个字节。

您将不得不按块写入CLOB块。就像这样:

$ $ p $ DECLARE
v_clob CLOB;
v_clob_length INTEGER;
pos INTEGER:= 1;
buffer VARCHAR2(32767);
amount BINARY_INTEGER:= 32760;
prodFeed_file utl_file.file_type;
BEGIN
prodFeed_file:= UTL_FILE.FOPEN('CSV_DIR','productFeedLargo.xml','w',32767);
v_clob:= l_xmltype.getClobVal;
v_clob_length:= length(v_clob);

WHILE pos< v_clob_length LOOP
dbms_lob.read(v_clob,amount,pos,buffer);
utl_file.put(prodFeed_file,char_buffer);
utl_file.fflush(prodFeed_file);
pos:= pos + amount;
END LOOP;

utl_file.fclose(prodFeed_file);

END;
/


I created a xml which includes a big amount of data. Now I am trying to write that generated xml into a file.

Declaration:

prodFeed_file  UTL_FILE.FILE_TYPE;
prodFeed_file := UTL_FILE.FOPEN ('CSV_DIR', 'feed.xml', 'w', 32767); 

WRITING INTO FILE:

UTL_FILE.PUT_LINE(prodFeed_file,l_xmltype.getClobVal);

UTL_FILE.FCLOSE(prodFeed_file);

If l_xmltype.getClobVal returns limited record then it is working file but if the l_xmltype.getClobVal exceeds the size(almost 35 KB) it is giving an error:

ORA-06502: PL/SQL: numeric or value error

解决方案

The UTL_FILE documentation says:

"The maximum size of the buffer parameter is 32767 bytes unless you specify a smaller size in FOPEN. "

You will have to write the CLOB chunk by chunk. Something like this:

DECLARE
  v_clob CLOB;
  v_clob_length INTEGER;
  pos INTEGER := 1;
  buffer VARCHAR2(32767);
  amount BINARY_INTEGER := 32760;
  prodFeed_file utl_file.file_type;
BEGIN
  prodFeed_file := UTL_FILE.FOPEN ('CSV_DIR', 'productFeedLargo.xml', 'w', 32767);
  v_clob := l_xmltype.getClobVal;
  v_clob_length := length(v_clob);

  WHILE pos < v_clob_length LOOP
    dbms_lob.read(v_clob, amount, pos, buffer);
    utl_file.put(prodFeed_file , char_buffer);
    utl_file.fflush(prodFeed_file);
    pos := pos + amount;
  END LOOP;

  utl_file.fclose(prodFeed_file);

END;
/

这篇关于不能用UTL_FILE.PUT_LINE写出大尺寸的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆