将逻辑添加到SQL * Loader控制文件以加载特定列

问题描述 投票:1回答:1

我有一个控制文件。我正在尝试为“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"
 )
oracle oracle11g sql-loader
1个回答
2
投票

您可以使用CASE,例如在此示例中。

一,样本表:

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>
© www.soinside.com 2019 - 2024. All rights reserved.