Using pl/sql how do I locate a file in a directory and move the file?
Using 开发者_如何学编程pl/sql how do I locate a file in a directory and move the file?
To test if a file exists, you can use UTL_FILE.fGetAttr
. Docs
For example:
DECLARE
l_file_exists BOOLEAN;
l_file_len NUMBER;
l_blocksize BINARY_INTEGER;
BEGIN
utl_file.fgetattr(
location => 'MYDIRECTORY',
filename => 'myfilename.ext',
fexists => l_file_exists,
file_length => l_file_len,
block_size => l_blocksize);
IF l_file_exists THEN
dbms_output.put_line('File found, size=' || l_file_len);
ELSE
dbms_output.put_line('File not found.');
END IF;
END;
To rename a file, you can use UTL_FILE.fRename
. Docs
For example:
BEGIN
UTL_FILE.FRENAME (
src_location => 'FROMDIRECTORY',
src_filename => 'filename.ext',
dest_location => 'TODIRECTORY',
dest_filename => 'filename.ext',
overwrite => FALSE);
END;
精彩评论