一个简单的NVL 函数调用就可以完成这项工作。
这是一个例子:
SQL> create table test (col0 number, col1 varchar2(10), col2 number);
Table created.
控制文件:注意col2 "nvl(:col2, :col0)",如果col2 不存在,它将把col0 值放入col2。在我的示例中,它是第二行 2,yyy,,它不包含 col2 的值,因此它将填充 col0 值,即 2。
load data
infile *
replace
into table test
fields terminated by ","
trailing nullcols
(
col0,
col1,
col2 "nvl(:col2, :col0)"
)
begindata
1,xxx,111
2,yyy,
3,zzz,333
加载会话和结果:
SQL> $sqlldr scott/tiger@xe control=test02.ctl log=test02.log
SQL*Loader: Release 11.2.0.2.0 - Production on Pet Kol 17 21:48:59 2018
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
Commit point reached - logical record count 2
Commit point reached - logical record count 3
SQL> select * From test;
COL0 COL1 COL2
---------- ---------- ----------
1 xxx 111
2 yyy 2
3 zzz 333
SQL>