utl_file and empty files [message #37302] |
Wed, 30 January 2002 06:10 |
Fabio
Messages: 23 Registered: October 2001
|
Junior Member |
|
|
Hi,
this is my problem: I must write a log file of db operations using utl_file.put_line(),but only at the first time that I write to the file,I want to put a description line. How can I test if the file is empty?
Can You help me??
Sincerly Fabio
|
|
|
Re: utl_file and empty files [message #37305 is a reply to message #37302] |
Wed, 30 January 2002 07:01 |
Suresh Vemulapalli
Messages: 624 Registered: August 2000
|
Senior Member |
|
|
try this:
DECLARE
fileHandler UTL_FILE.FILE_TYPE;
FUNCTION isempty(dir varchar2,fil varchar2) return boolean IS
fileid UTL_FILE.FILE_TYPE;
l_str varchar2(4000);
begin
fileid := UTL_FILE.FOPEN(dir, fil, 'r');
utl_file.get_line(fileid,l_str);
utl_file.fclose(fileid);
return false;
exception
when no_data_found then
utl_file.fclose(fileid);
return true;
end;
BEGIN
fileHandler := UTL_FILE.FOPEN('c:', 'x3.txt', 'a',32767);
If isempty('c:', 'x3.txt') THEN
utl_file.put_line(fileHandler,'description');
else
utl_file.put_line(fileHandler,'log info');
end if;
utl_file.fclose(fileHandler);
EXCEPTION
WHEN others then
utl_file.fclose(fileHandler);
end;
|
|
|