0

我使用外部表从系统中的文件夹中读取文件。

读取文件后,当我尝试将读取的文件移动到存档时,出现 FILE IN USE 错误。

是否有关闭文件或外部表中的东西的机制。

4

1 回答 1

2

我无法重现你的经历。请提供更详细的测试用例,包括操作系统和完整的 Oracle 错误消息等相关细节,包括编号。

给定对操作系统目录的读写访问权限...

SQL> select * from all_directories
  2  where directory_name like 'DATA%'
  3  /

OWNER  DIRECTORY_NAME  DIRECTORY_PATH
------ --------------- ------------------------
SYS    DATA_DROP       /home/oracle/drop_zone


SQL> 

...我创建了这张表...

create table t42_ext  (
    field1   number,
    field2   varchar2(20)
)
organization external
(
        type oracle_loader
        default directory data_drop
        access parameters 
        (
                records delimited by newline
                fields terminated by ','
                missing field values are null
        )
        location ('data20140923.txt')
)
reject limit unlimited;

...我可以查询:

SQL> select * from t42_ext;

    FIELD1 FIELD2
---------- --------------------
        23  'some data'

SQL>

然后,在一个单独的操作系统会话中,我移动了文件:

[oracle@localhost ~]$ cd drop_zone
[oracle@localhost drop_zone]$ ls
data20140923.txt  T42_EXT_3295.log
[oracle@localhost drop_zone]$ mv data20140923.txt ../data_archive
[oracle@localhost drop_zone]$ ls
T42_EXT_3295.log
[oracle@localhost drop_zone]$ 

回到数据库我不能再查询表:

SQL> r
  1* select * from t42_ext
select * from t42_ext
              *
ERROR at line 1:
ORA-29913: error in executing ODCIEXTTABLEOPEN callout
ORA-29400: data cartridge error
KUP-04040: file data20140923.txt in DATA_DROP not found

SQL>

替代方案,来自数据库内的文件操作,仍未重现。

重置:

SQL> select * from t42_ext;

    FIELD1 FIELD2
---------- --------------------
        23  'some data'

SQL> begin
    utl_file.frename(
           src_location     => 'DATA_DROP',
           src_filename     => 'data20140923.txt', 
           dest_location    => 'DATA_ARCH',
           dest_filename    => 'data20140923.txt',
           overwrite        => FALSE);
end;
/
  2    3    4    5    6    7    8    9  
PL/SQL procedure successfully completed.

SQL> select * from t42_ext;
select * from t42_ext
              *
ERROR at line 1:
ORA-29913: error in executing ODCIEXTTABLEOPEN callout
ORA-29400: data cartridge error
KUP-04040: file data20140923.txt in DATA_DROP not found


SQL> 
于 2014-09-23T05:38:09.247 回答