【发布时间】:2019-08-11 11:16:21
【问题描述】:
我在一个小程序中工作,该程序应该读取文件并验证文件是否为空或不存在。验证有效,但我试图实现读取,它抛出了以下错误:
ORA-29284: file read error
ORA-06512: at "SYS.UTL_FILE", line 106
ORA-06512: at "SYS.UTL_FILE", line 746
ORA-06512: at "HCM_ESTRUCTURES", line 23
ORA-06512: at line 3
我的代码:
CREATE OR REPLACE PROCEDURE hcm_estructures AS
/*-Files validation variables-*/
l_file_exists BOOLEAN;
l_file_len NUMBER;
l_blocksize BINARY_INTEGER;
/*Variables read file*/
v_archivo utl_file.file_type;
v_linea clob;
v_path varchar2(100):= 'PREPROCESSOR_DIRECTORY';
BEGIN
utl_file.fgetattr(
location => v_path,
filename => 'Worker_19032019.dat',
fexists => l_file_exists,
file_length => l_file_len,
block_size => l_blocksize);
if l_file_exists then
if l_file_len > 0 then
--dbms_output.put_line('The file will read correctly');
v_archivo := utl_file.fopen ('PREPROCESSOR_DIRECTORY', 'Worker_19032019.dat', 'r',32767);
loop
utl_file.get_line (v_archivo, v_linea);
dbms_output.put_line (v_linea);
end loop;
--utl_file.fclose(v_archivo);
else
dbms_output.put_line('The file is empty');
end if;
else
dbms_output.put_line('The file does not exists');
end if;
END;
程序只打印文件的一部分内容,然后显示错误。
【问题讨论】:
-
当你读到文件末尾时,你应该得到“ORA-01403: no data found”...文件有多大,有多少被读取/显示(即如何许多成功的
read_line调用在失败之前就已经存在),它包含什么样的数据——尤其是在失败点附近?文件中一行的最大长度是多少 - 可以超过 32767 个字符吗?
标签: stored-procedures plsql oracle11g utl-file