Sqlldr选项卡delim文件加载问题

时间:2019-07-02 05:24:54

标签: oracle sql-loader

我正在尝试将制表符delim文件加载到表中。 请检查以下问题并寻求帮助。

LOAD DATA
INFILE 'tab1.txt'
BADFILE 'tab1.bad'
DISCARDFILE 'tab1.dsc'
REPLACE INTO TABLE CL_TAB1 
FIELDS TERMINATED BY X'9' OPTIONALLY ENCLOSED BY '"'
TRAILING NULLCOLS
(
A,B,C,D,E
)

tab1.txt文件如下

A   B   C   D   E
799 CP  AM  27-12-2017
800 CP      18-05-2017
801             USA     
  1. 如果我不使用列名提及TRAILING NULLCOLS,则sqlldr仅将空值加载到表中。
  2. 当我在TRAILING NULLCOLS中列出了列名时,sqlldr会像表中的下面所示加载。

A   B   C   D   E
799 CP  AM  27-12-2017      (Note: this is ok record)
800 CP  18-05-2017          (Note: 18-05-2017 should be loaded onto D col, but loaded onto C)
801 USA                     (Note: USA should be loaded onto E col, but loaded onto B)

请帮助。

1 个答案:

答案 0 :(得分:1)

如果您不提及OPTIONALLY ENCLOSED BY '"'-> SQLLDR正常工作。

请参阅我的示例:

DDL

DROP TABLE TAB1;

CREATE TABLE TAB1 (
    A   VARCHAR2(100),
    B   VARCHAR2(100),
    C   VARCHAR2(100),
    D   VARCHAR2(100),
    E   VARCHAR2(100)
);

Tab1.txt

A   B   C   D   E
799 CP  AM  27-12-2017
800 CP      18-05-2017
801             USA

控制文件

LOAD DATA
INFILE 'tab1.txt'
BADFILE 'tab1.bad'
DISCARDFILE 'tab1.dsc'
REPLACE INTO TABLE TAB1 
FIELDS TERMINATED BY X'9'
TRAILING NULLCOLS
(
A,B,C,D,E
)

SQLLDR执行

>sqlldr userid=tejash/***** control=tab1.ctl

SQL*Loader: Release 12.2.0.1.0 - Production on Tue Jul 2 11:43:33 2019

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

Path used:      Conventional
Commit point reached - logical record count 3
Commit point reached - logical record count 4

Table TAB1:
  4 Rows successfully loaded.

Check the log file:
  tab1.log
for more information about the load.

表TAB1中的数据

A   B   C   D   E
799 CP  AM  27-12-2017  
800 CP      18-05-2017  
801             USA

enter image description here

文本文件的第一行只是标题,如果要跳过标题,则需要在控制文件中使用OPTIONS(skip=1)