Get file attribute

There are many simple way to find wheter a file exist in some directory or not. In plSQL, using UTL_FILE package is the answer. Beside to read and to write file UTL_FILE could find a file attribute using FGETATTR. Here is the command :

UTL_FILE.FGETATTR(
location IN VARCHAR2,
filename IN VARCHAR2,
exists OUT BOOLEAN,
file_length OUT NUMBER,
blocksize OUT NUMBER);

If I put it into complete script it could be like this
DECLARE
l_exists BOOLEAN;
l_length NUMBER;
l_blocksize NUMBER;
BEGIN
UTL_FILE.FGETATTR(‘/testbad/’, ‘dmpfile.dmp’, l_exists, l_length, l_blocksize);
IF l_exists THEN
dbms_output.put_line(‘filesize is: ‘||l_length);
dbms_output.put_line(‘block size is: ‘||l_blocksize);
ELSE
dbms_output.put_line(‘not found.’);
END IF;
END;
/
and the result if file exist is :

filesize is:6934528
block size is:31249

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s