无法使用dbms_lob.filopen打开文件,但可以使用utl_file打开它

时间:2012-06-06 13:51:49

标签: oracle

可能导致以下行为:

数据库11gR2

declare
   l_amt        number := dbms_lob.lobmaxsize;
   l_dst_loc    clob;
   l_dst_offset number := 1;
   l_lang_ctx   number := dbms_lob.default_lang_ctx;
   l_src_loc    bfile;
   l_src_offset number := 1;
   l_warning    number;
begin

   l_src_loc := bfilename('ODS_SERVER_DIRECTORY', '_CIVKD_ASU.CSV');
   dbms_lob.createtemporary(l_dst_loc, true);
   dbms_lob.fileopen(l_src_loc, dbms_lob.file_readonly);
   dbms_lob.loadclobfromfile(l_dst_loc
                            ,l_src_loc
                            ,l_amt
                            ,l_dst_offset
                            ,l_src_offset
                            ,dbms_lob.default_csid
                            ,l_lang_ctx
                            ,l_warning);
   commit;

   dbms_lob.fileclose(l_src_loc);
   dbms_output.put_line(substr(l_dst_loc, 1, 200));

end;
/ 

ORA-22288: file or LOB operation FILEOPEN failed
.
ORA-06512: in "SYS.DBMS_LOB", line 805
ORA-06512: in line 31
22288. 00000 -  "file or LOB operation %s failed\n%s"
*Cause:    The operation attempted on the file or LOB failed.
*Action:   See the next error message in the error stack for more detailed
           information.  Also, verify that the file or LOB exists and that
           the necessary privileges are set for the specified operation. If
           the error still persists, report the error to the DBA.

但是,使用utl_file时,打开并读取完全相同的文件会成功。

declare
   l_file utl_file.file_type;
   l_regel varchar2(4000);
begin

   l_file := utl_file.fopen('ODS_SERVER_DIRECTORY', '_CIVKD_ASU.CSV', 'R');
   -- Haal de volgende regel op
   utl_file.get_line(l_file, l_regel);

   dbms_output.put_line(l_regel);
   utl_file.fclose_all;
end;

因此,数据库似乎可以访问该文件。

这是我们第一次遇到这个特殊的错误而且它是最早的11gR2实例之一,所以也许有一些我们不知道的具体内容?

===更新8-6-2012 === 取得了一些进展。事实证明,目录对象指向共享驱动器。它是一个Windows服务器,Oracle作为本地系统运行。我一直认为在这种情况下无法从共享驱动器中读取任何内容。显然在某些情况下你可以使用utl_file但不能使用dbms_lob。

1 个答案:

答案 0 :(得分:1)

您能否确认ODS_SERVER_DIRECTORY是实际的DIRECTORY

SELECT 
    *
FROM
    dba_objects
WHERE
    object_type = 'DIRECTORY'
    AND object_name = 'ODS_SERVER_DIRECTORY'

可能你在init.ora的UTL_FILE_DIR参数中设置了它(不应该再做了..)

但它有可能为什么utl_file会看到目录而dbms_lob不会。