xml – 无法使用UTL_FILE.PUT_LINE写入大尺寸数据

前端之家收集整理的这篇文章主要介绍了xml – 无法使用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:数值或值错误

解决方法

UTL_FILE documentation says

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

您将不得不按块编写CLOB块.像这样的东西:

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',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;
/

猜你在找的XML相关文章