Sql 正在尝试使用utl_文件方法读取文件

Sql 正在尝试使用utl_文件方法读取文件,sql,oracle,plsql,utl-file,Sql,Oracle,Plsql,Utl File,我正在尝试查看此文件是否存在。但是我收到了这个错误信息。我已经检查了我获得的特权。但是这个文件在服务器端,所以我有什么遗漏吗 DECLARE vInHandle utl_file.file_type; BEGIN vInHandle := utl_file.fopen('IMG_UTL_DIR', 'image-file.csv', 'R'); IF utl_file.is_open(vInHandle) THEN dbms_output.put_line('T

我正在尝试查看此文件是否存在。但是我收到了这个错误信息。我已经检查了我获得的特权。但是这个文件在服务器端,所以我有什么遗漏吗

DECLARE
  vInHandle  utl_file.file_type;

BEGIN

  vInHandle := utl_file.fopen('IMG_UTL_DIR', 'image-file.csv', 'R');

  IF utl_file.is_open(vInHandle) THEN

      dbms_output.put_line('The File exists');

  Else

      dbms_output.put_line('The File not  exists');
  END IF;
END fopen;
错误:

ORA-29283:无效的文件操作
ORA-06512:在“SYS.UTL_文件”第536行
ORA-29283:无效的文件操作
ORA-06512:在第5行


如果该文件不存在,则会出现该错误。使用您的代码,当文件存在时,您将获得:

anonymous block completed
The File exists
Error report -
ORA-29283: invalid file operation
ORA-06512: at "SYS.UTL_FILE", line 536
ORA-29283: invalid file operation
ORA-06512: at line 6
29283. 00000 -  "invalid file operation"
*Cause:    An attempt was made to read from a file or directory that does
           not exist, or file or directory access was denied by the
           operating system.
*Action:   Verify file and directory access privileges on the file system,
           and if reading, verify that the file exists.
但当文件不存在时,您将获得:

anonymous block completed
The File exists
Error report -
ORA-29283: invalid file operation
ORA-06512: at "SYS.UTL_FILE", line 536
ORA-29283: invalid file operation
ORA-06512: at line 6
29283. 00000 -  "invalid file operation"
*Cause:    An attempt was made to read from a file or directory that does
           not exist, or file or directory access was denied by the
           operating system.
*Action:   Verify file and directory access privileges on the file system,
           and if reading, verify that the file exists.
请注意错误描述中的“不存在的文件或目录”部分。不能像这样测试文件是否存在。就我所知,没有直接的方法来测试文件是否存在;您必须尝试打开文件并捕获异常。例如:

DECLARE
  vInHandle  utl_file.file_type;
  eNoFile    exception;
  PRAGMA exception_init(eNoFile, -29283);
BEGIN
  BEGIN
    vInHandle := utl_file.fopen('IMG_UTL_DIR', 'image-file.csv', 'R');
    dbms_output.put_line('The File exists');
  EXCEPTION
    WHEN eNoFile THEN
      dbms_output.put_line('The File not  exists');
  END;
END fopen;
/

anonymous block completed
The File not  exists
但是ORA-29283异常也可能意味着其他事情,正如描述中所说,因此它不一定意味着文件不在那里-它可能在那里,但由于某些其他(与权限相关的)原因无法访问。您还将在某种程度上屏蔽实际错误的位置,如果块中有多个文件操作,则必须将每个操作包装在其自己的开始/异常/结束子块中以指定错误,或者丢失实际错误点


您最好让异常自然地引发和报告,而不是捕获它并用客户端可能无法检索和显示的
dbms\u输出
消息替换它。

如果该文件不存在,您将得到该错误。使用您的代码,当文件存在时,您将获得:

anonymous block completed
The File exists
Error report -
ORA-29283: invalid file operation
ORA-06512: at "SYS.UTL_FILE", line 536
ORA-29283: invalid file operation
ORA-06512: at line 6
29283. 00000 -  "invalid file operation"
*Cause:    An attempt was made to read from a file or directory that does
           not exist, or file or directory access was denied by the
           operating system.
*Action:   Verify file and directory access privileges on the file system,
           and if reading, verify that the file exists.
但当文件不存在时,您将获得:

anonymous block completed
The File exists
Error report -
ORA-29283: invalid file operation
ORA-06512: at "SYS.UTL_FILE", line 536
ORA-29283: invalid file operation
ORA-06512: at line 6
29283. 00000 -  "invalid file operation"
*Cause:    An attempt was made to read from a file or directory that does
           not exist, or file or directory access was denied by the
           operating system.
*Action:   Verify file and directory access privileges on the file system,
           and if reading, verify that the file exists.
请注意错误描述中的“不存在的文件或目录”部分。不能像这样测试文件是否存在。就我所知,没有直接的方法来测试文件是否存在;您必须尝试打开文件并捕获异常。例如:

DECLARE
  vInHandle  utl_file.file_type;
  eNoFile    exception;
  PRAGMA exception_init(eNoFile, -29283);
BEGIN
  BEGIN
    vInHandle := utl_file.fopen('IMG_UTL_DIR', 'image-file.csv', 'R');
    dbms_output.put_line('The File exists');
  EXCEPTION
    WHEN eNoFile THEN
      dbms_output.put_line('The File not  exists');
  END;
END fopen;
/

anonymous block completed
The File not  exists
但是ORA-29283异常也可能意味着其他事情,正如描述中所说,因此它不一定意味着文件不在那里-它可能在那里,但由于某些其他(与权限相关的)原因无法访问。您还将在某种程度上屏蔽实际错误的位置,如果块中有多个文件操作,则必须将每个操作包装在其自己的开始/异常/结束子块中以指定错误,或者丢失实际错误点


您最好让异常自然地引发和报告,而不是捕获它并用客户端可能无法检索和显示的
dbms\u输出
消息替换它。

如果该文件不存在,您将得到该错误。使用您的代码,当文件存在时,您将获得:

anonymous block completed
The File exists
Error report -
ORA-29283: invalid file operation
ORA-06512: at "SYS.UTL_FILE", line 536
ORA-29283: invalid file operation
ORA-06512: at line 6
29283. 00000 -  "invalid file operation"
*Cause:    An attempt was made to read from a file or directory that does
           not exist, or file or directory access was denied by the
           operating system.
*Action:   Verify file and directory access privileges on the file system,
           and if reading, verify that the file exists.
但当文件不存在时,您将获得:

anonymous block completed
The File exists
Error report -
ORA-29283: invalid file operation
ORA-06512: at "SYS.UTL_FILE", line 536
ORA-29283: invalid file operation
ORA-06512: at line 6
29283. 00000 -  "invalid file operation"
*Cause:    An attempt was made to read from a file or directory that does
           not exist, or file or directory access was denied by the
           operating system.
*Action:   Verify file and directory access privileges on the file system,
           and if reading, verify that the file exists.
请注意错误描述中的“不存在的文件或目录”部分。不能像这样测试文件是否存在。就我所知,没有直接的方法来测试文件是否存在;您必须尝试打开文件并捕获异常。例如:

DECLARE
  vInHandle  utl_file.file_type;
  eNoFile    exception;
  PRAGMA exception_init(eNoFile, -29283);
BEGIN
  BEGIN
    vInHandle := utl_file.fopen('IMG_UTL_DIR', 'image-file.csv', 'R');
    dbms_output.put_line('The File exists');
  EXCEPTION
    WHEN eNoFile THEN
      dbms_output.put_line('The File not  exists');
  END;
END fopen;
/

anonymous block completed
The File not  exists
但是ORA-29283异常也可能意味着其他事情,正如描述中所说,因此它不一定意味着文件不在那里-它可能在那里,但由于某些其他(与权限相关的)原因无法访问。您还将在某种程度上屏蔽实际错误的位置,如果块中有多个文件操作,则必须将每个操作包装在其自己的开始/异常/结束子块中以指定错误,或者丢失实际错误点


您最好让异常自然地引发和报告,而不是捕获它并用客户端可能无法检索和显示的
dbms\u输出
消息替换它。

如果该文件不存在,您将得到该错误。使用您的代码,当文件存在时,您将获得:

anonymous block completed
The File exists
Error report -
ORA-29283: invalid file operation
ORA-06512: at "SYS.UTL_FILE", line 536
ORA-29283: invalid file operation
ORA-06512: at line 6
29283. 00000 -  "invalid file operation"
*Cause:    An attempt was made to read from a file or directory that does
           not exist, or file or directory access was denied by the
           operating system.
*Action:   Verify file and directory access privileges on the file system,
           and if reading, verify that the file exists.
但当文件不存在时,您将获得:

anonymous block completed
The File exists
Error report -
ORA-29283: invalid file operation
ORA-06512: at "SYS.UTL_FILE", line 536
ORA-29283: invalid file operation
ORA-06512: at line 6
29283. 00000 -  "invalid file operation"
*Cause:    An attempt was made to read from a file or directory that does
           not exist, or file or directory access was denied by the
           operating system.
*Action:   Verify file and directory access privileges on the file system,
           and if reading, verify that the file exists.
请注意错误描述中的“不存在的文件或目录”部分。不能像这样测试文件是否存在。就我所知,没有直接的方法来测试文件是否存在;您必须尝试打开文件并捕获异常。例如:

DECLARE
  vInHandle  utl_file.file_type;
  eNoFile    exception;
  PRAGMA exception_init(eNoFile, -29283);
BEGIN
  BEGIN
    vInHandle := utl_file.fopen('IMG_UTL_DIR', 'image-file.csv', 'R');
    dbms_output.put_line('The File exists');
  EXCEPTION
    WHEN eNoFile THEN
      dbms_output.put_line('The File not  exists');
  END;
END fopen;
/

anonymous block completed
The File not  exists
但是ORA-29283异常也可能意味着其他事情,正如描述中所说,因此它不一定意味着文件不在那里-它可能在那里,但由于某些其他(与权限相关的)原因无法访问。您还将在某种程度上屏蔽实际错误的位置,如果块中有多个文件操作,则必须将每个操作包装在其自己的开始/异常/结束子块中以指定错误,或者丢失实际错误点


您最好让异常自然地引发和报告,而不是捕获异常并用
dbms\u输出
消息替换它,因为客户端可能无法检索和显示该消息。

否,因此应该引用它。该目录对象是否存在,您是否对该对象具有权限,服务器操作系统中是否存在基础目录,Oracle是否有权访问该目录;这个文件真的存在吗?你说你正在测试,但如果没有,那么它就会出错。我一下子记不起来你是否被允许以大写字母通过模式-文档只显示小写。@AlexPoole-我被纠正了。在我们的商店里,DBA拒绝让我们使用目录对象(“它们是一个潜在的安全风险”。WTF?!但我该和谁争论…:-/)所以我们仍然在打开带有目录路径的文件-请不要问我这如何“更好”或“更安全”-这些东西超出了像我这样的凡人的理解。不,所以应该引用它。是吗