Read Last Line of a log file Using UTL_FILE
Hi All,
My Environment is -------> Oracle 11g Database Release 1 On Windows 2003 Server SP2.
Requirement is ------------> Read Last Line of a Log file Using UTL_FILE.
I am trying to read last line of a log file which is generated by our own application. I am able to get the last line using the below script but the problem is in the Log file, has some blank lines at the end. so i am getting the output as blank.
Script
Declare
DIRECTORY VARCHAR2 (300) := 'BACKUP';
filename VARCHAR2 (300) := 'Client_Log_02-05-2011.log';
l_file UTL_FILE.file_type;
l_text VARCHAR2 (32767);
BEGIN
l_file := UTL_FILE.fopen (DIRECTORY, filename, 'r', 32767);
UTL_FILE.get_line (l_file, l_text, 32767);
--DBMS_OUTPUT.put_line ('First Line: |' || l_text || '|');
BEGIN
LOOP
UTL_FILE.get_line (l_file, l_text, 32767);
END LOOP;
EXCEPTION
WHEN NO_DATA_FOUND
THEN
NULL;
END;
DBMS_OUTPUT.put_line ('Last Line : |' || l_text || '|');
UTL_FILE.fclose (l_file);
END;
Please Advice me how to skip/ignore the blank lines... if u r having any web links or any scripts please share it.
Thank you for your help
Shan