Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Read Last Line of a log file Using UTL_FILE

SHAN2009May 2 2011 — edited May 5 2011
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
This post has been answered by 792754 on May 2 2011
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 2 2011
Added on May 2 2011
3 comments
1,868 views