l_directory VARCHAR2(20) := 'MYDIR'; l_file_name VARCHAR2(20) := '1.txt'; l_file utl_file.file_type; l_clob CLOB; l_len PLS_INTEGER; l_pos INTEGER := 1; l_buffer VARCHAR2(32767); l_amount BINARY_INTEGER := 32760; BEGIN FOR i IN 1 .. 5000 l_clob := l_clob || '0123456789'; END LOOP; l_len := dbms_lob.getlength(l_clob); --此处如果是W方式就会报错 ORA-29285: file write error l_file := utl_file.fopen(l_directory, l_file_name, 'wb', 32767); WHILE l_pos < l_len LOOP dbms_lob.READ(l_clob, l_amount, l_pos, l_buffer); utl_file.put_raw(l_file, utl_raw.cast_to_raw(l_buffer)); utl_file.fflush(l_file); l_pos := l_pos + l_amount; END LOOP; utl_file.fclose(l_file); EXCEPTION WHEN OTHERS THEN dbms_output.put_line(SQLERRM);

原因参考:Attempting to Write CLOB Data Larger Than 32KB Using UTL_FILE Fails With: ORA-29285 (Doc ID 358422.1)

CAUSE
UTL_FILE.PUT has been used to write a CLOB data of size more than 32KB without flushing the buffer

While writing into an ASCII file, the buffer will be flushed only after new line character is encountered. >If a new line character is not written before closing, then CLOSE() does this. However if the current buffer exceeds the maximum allowed for a line in an ASCII file then CLOSE() raises this write error.

SOLUTION

  1. Open the file in ‘wb’ mode instead of ‘w’ mode.
  2. Use UTL_FILE.PUT_RAW instead of UTL_FILE.PUT

dbms_lob参考

使用UTL_FILE写超过32k的数据时报错 ORA-29285: file write error例子:DECLARE l_directory VARCHAR2(20) := 'MYDIR'; l_file_name VARCHAR2(20) := '1.txt'; l_file utl_file.file_type; l_clob CLOB; l_len ...
问题: 使用 存储过程将 数据 转为txt文件 报: ORA - 29285 : 文件 入错误 ORA -06512: 在 "SYS. UTL _ FILE ", line 148 ORA -06512: 在 "SYS. UTL _ FILE ", line 889 ORA -06512: 在 "*** FILE ", line *** ORA -06512: 在 "*** FILE ", line *** 分析:第一条 数据 记录成功,第二条...
使用 Ora cle脚本对 数据 数据 进行格式化导出的 候出现下列 报错 。 1. 首先检查 文件路径是否给了权限 2. 如果一条 数据 数据 长度较大,需要修改缓存使得 文件操作能进行 ORA - 29285 : file write error ORA -06512: at "SYS. UTL _ FILE ", line 140 ORA -06512: at "SYS. UTL _ FILE ", line 37
ORA - 29285 : 文件 入错误 运行 -》 regedit -》查找 键值 NLS_LANG 将字符集 SIMPLIFIED CHINESE_CHINA.ZHS16GBK 修改为AMERICAN_AMERICA.AL32UTF8 注册表路径:HKEY_LOCAL_MACHINE\SOFTWARE\ ORA CLE\HO...
UTL _ FILE 包可以用来读 操作系统上的文件,提供了在客户端操作服务器端文件的功能。它提供一套严格的 使用 标准操作系统文件I/O方式:OPEN、PUT、GET和CLOSE操作;其中,GET方法用于读文件,PUT方法用于 文件。当用户读取或 入一个 数据 文件的 候,可以 使用 FOPEN返回的文件句柄,这个文件句柄将用于随后在文件上的所有操作,包含读、 、删除、重命名文件等。 本章介绍 使用 UTL _ FILE 系统文件的方法,从而可以利用 UTL _ FILE 将表 数据 导出到文本文件,也可以将文本文件 入表中。 错误原因: 数据 泵在 日志文件的 候, 使用 的是 数据 库字符集。如果客户端的环境变量NLS_LANG得值和 数据 库字符集不一致的话,日志中显示的表名称可能和终端屏幕输出的不一致。 数据 泵内部 使用 的是包 UTL _ FILE ,在和NLS转换的 候可能不能输出字符。 #查看测试库 ...
DECLARE -- 收件人邮箱地址 v_recipients VARCHAR2(100) := 'recipient1@example.com, recipient2@example.com'; -- 邮件主题 v_subject VARCHAR2(100) := 'Test Email'; -- 邮件内容 v_message VARCHAR2(4000) := 'This is a test email sent from an Ora cle stored procedure using UTL _MAIL.'; -- 发件人邮箱地址 v_sender VARCHAR2(100) := 'sender@example.com'; BEGIN UTL _MAIL.send( sender => v_sender, recipients => v_recipients, subject => v_subject, message => v_message 在上面的代码中,`v_recipients`变量包含收件人的邮箱地址,可以 使用 逗号分隔多个地址。`v_subject`变量包含邮件主题,`v_message`变量包含邮件内容,`v_sender`变量包含发件人的邮箱地址。 请注意,为了 使用 UTL _MAIL包,需要先配置SMTP服务器信息,可以 使用 以下代码配置: ```plsql BEGIN UTL _MAIL.SET_SMTP_HOST('smtp.example.com'); UTL _MAIL.SET_SMTP_PORT(25); 在上面的代码中,`SET_SMTP_HOST`过程设置SMTP服务器的主机名或IP地址,`SET_SMTP_PORT`过程设置SMTP服务器的端口号。具体设置应根据实际情况进行调整。