oracle 使用 pl/sql 如何在目录中定位文件并移动文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3597003/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 21:24:34  来源:igfitidea点击:

Using pl/sql how do I locate a file in a directory and move the file?

oraclefileplsql

提问by Kevin

Using pl/sql how do I locate a file in a directory and move the file?

使用 pl/sql 如何在目录中定位文件并移动文件?

回答by Jeffrey Kemp

To test if a file exists, you can use UTL_FILE.fGetAttr. Docs

要测试文件是否存在,您可以使用UTL_FILE.fGetAttr. 文档

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

要重命名文件,您可以使用UTL_FILE.fRename. 文档

For example:

例如:

BEGIN
  UTL_FILE.FRENAME (
    src_location  => 'FROMDIRECTORY',
    src_filename  => 'filename.ext', 
    dest_location => 'TODIRECTORY',
    dest_filename => 'filename.ext',
    overwrite     => FALSE);
END;