使用SQLLDR加载定界数据时跳过数据字段 [英] Skipping data fields while loading delimited data using SQLLDR

查看:2147
本文介绍了使用SQLLDR加载定界数据时跳过数据字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请考虑以下情形:

T1 (f1, f2, f3);

数据文件:

a|b|c|d
w|x|y|z

我想跳过第二个字段来加载此数据,如下所示:

I want to load this data skipping the second field as follow:

f1    f2    f3 
---   ---   ---
a     d     c
w     z     y

非常感谢您的帮助或为构建此控制文件而提供的任何指针.

Would really appreciate your help or any pointer in constructing the control file to achieve this.

推荐答案

将要跳过的列定义为FILLER.请记住,控制文件中列的顺序通常是它们在数据文件中的顺序.如果名称与表中的一列匹配,则它将在该位置.

Define the column you want to skip as FILLER. Keep in mind the order of the columns in the control file is typically the order they are in the datafile. If the name matches a column in the table, that's where it will go.

...
(
  f1 CHAR,  -- 1st field in the file, goes to column named f1 in the table
  X FILLER, -- 2nd field in the file, ignored
  f3 CHAR,  -- 3rd field in the file, goes to column named f3 in the table
  f2 CHAR   -- 4th field in the file, goes to column named f2 in the table
)

换句话说,控制文件中列的顺序与数据文件中的顺序匹配,而不是表中的顺序.那是按名称而不是顺序匹配的.

In other words, the order of the columns in the control file matches the order they are in the data file, not their order in the table. That is matched by name, not order.

编辑-我添加了一些注释以作解释,但我认为它们在实际文件中不能处于该位置.参见下面的完整示例:

EDIT - I added some comments for explanation, but I believe they can't be in that position in the actual file. See below for a full example:

创建表格:

CREATE TABLE T1
(
  F1  VARCHAR2(50 BYTE),
  F2  VARCHAR2(50 BYTE),
  F3  VARCHAR2(50 BYTE)
);

控制文件example.ctl:

The control file, example.ctl:

load data 
infile *
truncate
into table t1
fields terminated by '|' trailing nullcols
(
f1 CHAR,
x FILLER,
f3 CHAR,
f2 CHAR
)
BEGINDATA
a|b|c|d
w|x|y|z

运行它:

C:\temp>sqlldr userid=login/password@database control=example.ctl
SQL*Loader: Release 11.2.0.1.0 - Production on Wed Apr 22 11:25:49 2015
Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.
Commit point reached - logical record count 2

从表中选择:

希望这会有所帮助.

这篇关于使用SQLLDR加载定界数据时跳过数据字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆