oracle – 第一次记录的SQL加载程序错误

我正在尝试将文件中的数据加载到Oracle中的表中,但我只在第一条记录上收到错误,第二条记录正在插入.

记录1:拒绝 – 表Ing_Details错误,列INGREDIENT_ID.

        ORA-01722:无效的号码

这是控制文件

LOAD DATA
INFILE  'C:\Users\Appdata\Desktop\SQl Loader\ing1.txt'
BADFILE 'C:\Users\Appdata\Desktop\SQl Loader\bad_orders.txt'
INTO TABLE Ing_Details 
FIELDS
TERMINATED BY "\t"
OPTIONALLY ENCLOSED BY '"' 
     TRAILING NULLCOLS
( 
INGREDIENT_ID NULLIF INGREDIENT_TYPE_ID=BLANKS,
INGREDIENT_TYPE_ID NULLIF INGREDIENT_TYPE_ID=BLANKS,
Status NULLIF Status=BLANKS,
Organic NULLIF Organic=BLANKS
)

表结构

Ingredient_ID              NUMBER NOT NULL,
   Ingredient_Type_ID         NUMBER NOT NULL,
   Status                     NUMBER (10) NOT NULL,
   Organic                    NUMBER (10) NOT NULL

日志文件:

SQL*Loader: Release 11.2.0.2.0 - Production on Mon Jul 11 12:25:59 2016

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

Control File:   C:\Users\Appdata\Desktop\ingredient2.ctl
Data File:      C:\Users\Appdata\Desktop\SQl Loader\ing1.csv
  Bad File:     C:\Users\Appdata\Desktop\SQl Loader\bad_orders.txt
  Discard File:  none specified

 (Allow all discards)

Number to load: ALL
Number to skip: 0
Errors allowed: 50
Bind array:     64 rows, maximum of 256000 bytes
Continuation:    none specified
Path used:      Conventional

    Table Ing_Details, loaded from every logical record.
    Insert option in effect for this table: INSERT
    TRAILING NULLCOLS option in effect

       Column Name                  Position   Len  Term Encl Datatype
    ------------------------------ ---------- ----- ---- ---- ---------------------
    INGREDIENT_ID                       FIRST     *   ,  O(") CHARACTER            
        NULL if INGREDIENT_TYPE_ID = BLANKS
    INGREDIENT_TYPE_ID                   NEXT     *   ,  O(") CHARACTER            
        NULL if INGREDIENT_TYPE_ID = BLANKS
    STATUS                               NEXT     *   ,  O(") CHARACTER            
        NULL if STATUS = BLANKS
    ORGANIC                              NEXT     *   ,  O(") CHARACTER            
        NULL if ORGANIC = BLANKS

    Record 1: Rejected - Error on table Ing_Details, column INGREDIENT_ID.
    ORA-01722: invalid number

最佳答案 检查数据文件上的编码. SQLLDR似乎与BOM的UTF-8文件有问题,因为它在文件的开头添加了3个字节(
UTF-8 vs UTF-8 w/o BOM).这些字节包含在第一个定义的字段中(根据.ctl文件),Oracle无法将其转换为NUMBER.通过在数据文件中添加和跳过空白标题行,您基本上无效3个额外字节的效果.

检查文件编码的简便方法是在记事本中打开文件并打开编码菜单项.

如有必要,选择编码不带BOM的UTF-8来更改文件编码.

点赞