SQL加载器控制文件条件以格式化数据

时间:2016-08-05 13:56:21

标签: sql-loader

由于源文件END_DATE列中的“ - ”数据未插入表中。

我希望这可以在以下条件下工作。

IF '-' UPDATE END_DATE = NULL
ELSE END_DATE DATE "DD-MM-YYYY"

控制文件:

infile 'Test.csv'
append into table DATA.Test
fields terminated by ','
optionally enclosed by '"'
(
  EMPLOYEE_ID
  END_DATE DATE "DD-MM-YYYY"
)

来源数据:Test.csv

EMPLOYEE_ID,END_DATE DATE
"12345","-"  
"12346","12/11/2016"

1 个答案:

答案 0 :(得分:0)

您可以在控制文件中使用case语句,如下所示:

infile 'Test.csv'
append into table DATA.Test
fields terminated by ','
optionally enclosed by '"'
(
EMPLOYEE_ID,
END_DATE DATE "CASE WHEN :END_DATE = '-' THEN NULL 
                    ELSE to_date(:END_DATE, 'MM/DD/YYYY') 
               END"
)