小编典典

检查文件是否存在?

sql

尝试检查我要读取的文件是否存在。


阅读 139

收藏
2021-03-23

共1个答案

小编典典

这是另一种方法:

  1. 包装的用途BFILEfileexists功能dbms_lob

    create or replace function FileExists(
    

    p_DirName in varchar2, – schema object name
    p_FileName in varchar2
    ) return number
    is
    l_file_loc bfile;
    begin
    l_file_loc := bfilename(upper(p_DirName), p_FileName);
    return dbms_lob.fileexists(l_file_loc); – 1 exists; 0 - not exists
    end;

  2. 包使用fgetattr功能utl_file

    create or replace function FileExists(
    

    p_DirName in varchar2, – schema object name
    p_FileName in varchar2
    ) return number
    is
    l_fexists boolean;
    l_flen number;
    l_bsize number;
    l_res number(1);
    begin
    l_res := 0;
    utl_file.fgetattr(upper(p_DirName), p_FileName, l_fexists, l_flen, l_bsize);
    if l_fexists
    then
    l_res := 1;
    end if;
    return l_res;
    end;

2021-03-23