1

使用 Oracle SQL Loader 加载外部 csv 时,有没有办法将控制文件中的字段直接相互映射?

目前我正在做一个简单的加载,所以源字段的位置很重要。有没有办法做到这一点?所以而不是:

load data
into table1
fields terminated by "," optionally enclosed by '"'
(destination_field1, destination_field2, destination_field3)

做类似的事情:

load data
into table1
fields terminated by "," optionally enclosed by '"'
(
source_field2 => destination_field1,
source_field1 => destination_field2,
source_field3 => destination_field3
)

编辑:

主要原因是源文件中列的顺序可以改变,因此我不能确定哪个字段是第一个,第二个等。

4

1 回答 1

3

您可以在控制文件中包含通过 Oracle 函数进行的任何数据处理。
例如,此代码交换第 1 列和第 2 列并另外转换source_field2为数字,默默地将错误值替换为空值:

load data
append
into table SCHEMA.TABLE
fields terminated by ';' optionally enclosed by '"'
trailing nullcols
(
  source_field1     BOUNDFILLER,
  source_field2     BOUNDFILLER,
  source_field3     BOUNDFILLER,
  destination_field1 "to_number(regexp_substr(:source_field2, '^[-0-9,]*'),'9999999999D999','NLS_NUMERIC_CHARACTERS='', ''')",
  destination_field2 ":source_field1",
  destination_field3 ":source_field3"
)
于 2013-08-18T16:18:26.910 回答