外部表 - 丢弃文件未按预期生成

时间:2011-06-17 12:18:39

标签: oracle oracle11g sql-loader

我有一个带有以下定义的外部表。

create table app_doctor (
      doc_no             number(9),
      age                number(3),
      eor                char(3 char)
) 
organization external 
(     type oracle_loader
      default directory "DOC"
      access parameters
      ( 
        records delimited by newline
        **load when (eor = "EOR")**
        string sizes are in characters
        logfile 'doc.log'
        badfile 'doc.bad'
        discardfile 'doc.dsc'
        fields 
        ( 
          doc_no position     (1:9) integer external(9),
          age position        (10:12) integer external(3),
          eor position        (13:15) char(3)
        )
      )
      location('HOSP_DOC.txt')
)
reject limit unlimited
parallel 5;

我提供100条记录,其中50条有效,20条无效,30条不满足WHEN条件,但我在丢弃文件中只看到4条或5条记录。

3 个答案:

答案 0 :(得分:0)

使用以下外部表定义:

create table app_doctor (
      doc_no             number(9),
      age                number(3),
      eor                char(3 char)
) 
organization external 
(     type oracle_loader
      default directory "DOC"
      access parameters
      ( 
        records delimited by newline
        **load when (eor = "EOR")**
        string sizes are in characters
        logfile 'doc.log'
        badfile 'doc.bad'
        discardfile 'doc.dsc'
        fields 
        ( 
          doc_no position     (1:9) integer external(9),
          age position        (10:12) integer external(3),
          eor position        (13:15) char(3)
        )
      )
      location('HOSP_DOC.txt')
)
reject limit unlimited
parallel 5;

以下测试数据文件:

123456789021EOR
123456789021EOR
123456789021EOR
123456789021EOR
123456789021FER
123456789021FER
123456789021FER
asdfasfa9021ABC
asdfasfa9021ABC
asdfasfa9021ABCasdfasdas
123456789021ABC
123456789021FER
123456789021EOR
123456789021EOR
123456789021EOR
123456789021ABC
123456789021ABC
123456789021ABC

运行

时返回7条有效记录
select * from app_doctor;

我的丢弃文件包含所有11条错误记录,日志文件doc.log包含有关执行期间发生的错误的正确信息:

  LOG file opened at 03/08/13 11:33:56

Field Definitions for table APP_DOCTOR
  Record format DELIMITED BY NEWLINE
  Data in file has same endianness as the platform
  Rows with all null fields are accepted
  Load when (EOR = EOR)

  Fields in Data Source: 

    DOC_NO                          Integer external (9)
      Record position (1, 9)
      Trim whitespace same as SQL Loader
    AGE                             Integer external (3)
      Record position (10, 12)
      Trim whitespace same as SQL Loader
    EOR                             CHAR (3)
      Record position (13, 15)
      Trim whitespace same as SQL Loader


 LOG file opened at 03/08/13 11:33:56

Field Definitions for table APP_DOCTOR
  Record format DELIMITED BY NEWLINE
  Data in file has same endianness as the platform
  Rows with all null fields are accepted
  Load when (EOR = EOR)

  Fields in Data Source: 

    DOC_NO                          Integer external (9)
      Record position (1, 9)
      Trim whitespace same as SQL Loader
    AGE                             Integer external (3)
      Record position (10, 12)
      Trim whitespace same as SQL Loader
    EOR                             CHAR (3)
      Record position (13, 15)
      Trim whitespace same as SQL Loader
KUP-04102: record 5 discarded from file /apps/oracle/doc/HOSP_DOC.txt
KUP-04102: record 6 discarded from file /apps/oracle/doc/HOSP_DOC.txt
KUP-04102: record 7 discarded from file /apps/oracle/doc/HOSP_DOC.txt
KUP-04102: record 8 discarded from file /apps/oracle/doc/HOSP_DOC.txt
KUP-04102: record 9 discarded from file /apps/oracle/doc/HOSP_DOC.txt
KUP-04102: record 10 discarded from file /apps/oracle/doc/HOSP_DOC.txt
KUP-04102: record 11 discarded from file /apps/oracle/doc/HOSP_DOC.txt
KUP-04102: record 12 discarded from file /apps/oracle/doc/HOSP_DOC.txt
KUP-04102: record 16 discarded from file /apps/oracle/doc/HOSP_DOC.txt
KUP-04102: record 17 discarded from file /apps/oracle/doc/HOSP_DOC.txt
KUP-04102: record 18 discarded from file /apps/oracle/doc/HOSP_DOC.txt

答案 1 :(得分:0)

根据oracle documentation

  

DISCARDFILE子句指定要写入记录的文件   在LOAD WHEN子句中失败。

答案 2 :(得分:-1)

在eor ='EOR'的负载中,您可以删除它应该起作用的星号和括号