将逻辑添加到 SQL*Loader 控制文件以加载特定列
Adding Logic to SQL*Loader control file for loading a specific column
我有一个控制文件。我正在尝试为列 "QUALIFYING" 添加逻辑:
- 当值为NULL时,需要设置为‘F’。
- 当值为'x'时需要设置为'T'
options (ERRORS=1000, SKIP=1)
load data
infile '/clients/vca2/data/API/ADHOC_LOAD/MASTER_VCA_Reminder_setup_references.csv'
replace
into table VCABARK_CDI_DV.MASTER_REMINDER_SETUP
fields terminated by '|'
OPTIONALLY ENCLOSED BY '"' AND '"'
trailing nullcols
(
VI_Reminder_Id FILLER,
WW_Id,
Ranking,
WW_Desc ,
VS_Desc FILLER,
VCA_Client_Desc,
Do_Not_Display ,
Qualifying ,
IsNull,
Batch_Date expression "(SELECT RUNTIME FROM VCABARK_CDI_DV.RUNTIME_API)",
Region CONSTANT "US"
)
您可以使用 CASE
,例如本例。
先来个样例table:
SQL> create table test (id number, qualifying varchar2(10), isnull varchar2(1));
Table created.
控制文件:
load data
infile *
replace
into table test
fields terminated by "|" TRAILING NULLCOLS
(
id,
qualifying "case when :qualifying is null then 'F'
when :qualifying = 'x' then 'T'
else :qualifying
end",
isnull
)
begindata
1||y
2|x|y
3|225|n
测试:
SQL> $sqlldr scott/tiger@xe control=test05.ctl log=test05.log
SQL*Loader: Release 11.2.0.2.0 - Production on Pon O×u 25 16:49:56 2019
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
SQL*Loader-704: Internal error: ulconnect: OCIServerAttach [0]
ORA-12545: Connect failed because target host or object does not exist
SQL> $sqlldr scott/tiger control=test05.ctl log=test05.log
SQL*Loader: Release 11.2.0.2.0 - Production on Pon O×u 25 16:50:57 2019
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;
ID QUALIFYING I
---------- ---------- -
1 F y
2 T y
3 225 n
SQL>
我有一个控制文件。我正在尝试为列 "QUALIFYING" 添加逻辑:
- 当值为NULL时,需要设置为‘F’。
- 当值为'x'时需要设置为'T'
options (ERRORS=1000, SKIP=1)
load data
infile '/clients/vca2/data/API/ADHOC_LOAD/MASTER_VCA_Reminder_setup_references.csv'
replace
into table VCABARK_CDI_DV.MASTER_REMINDER_SETUP
fields terminated by '|'
OPTIONALLY ENCLOSED BY '"' AND '"'
trailing nullcols
(
VI_Reminder_Id FILLER,
WW_Id,
Ranking,
WW_Desc ,
VS_Desc FILLER,
VCA_Client_Desc,
Do_Not_Display ,
Qualifying ,
IsNull,
Batch_Date expression "(SELECT RUNTIME FROM VCABARK_CDI_DV.RUNTIME_API)",
Region CONSTANT "US"
)
您可以使用 CASE
,例如本例。
先来个样例table:
SQL> create table test (id number, qualifying varchar2(10), isnull varchar2(1));
Table created.
控制文件:
load data
infile *
replace
into table test
fields terminated by "|" TRAILING NULLCOLS
(
id,
qualifying "case when :qualifying is null then 'F'
when :qualifying = 'x' then 'T'
else :qualifying
end",
isnull
)
begindata
1||y
2|x|y
3|225|n
测试:
SQL> $sqlldr scott/tiger@xe control=test05.ctl log=test05.log
SQL*Loader: Release 11.2.0.2.0 - Production on Pon O×u 25 16:49:56 2019
Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.
SQL*Loader-704: Internal error: ulconnect: OCIServerAttach [0]
ORA-12545: Connect failed because target host or object does not exist
SQL> $sqlldr scott/tiger control=test05.ctl log=test05.log
SQL*Loader: Release 11.2.0.2.0 - Production on Pon O×u 25 16:50:57 2019
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;
ID QUALIFYING I
---------- ---------- -
1 F y
2 T y
3 225 n
SQL>