2016-08-05 36 views
0

由於源文件中END_DATE列中的「 - 」數據未插入到表中。用於格式化數據的SQL加載程序控制文件條件

我希望它能夠在下面的條件下工作。

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" 

回答

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" 
) 
+0

謝謝加里,它對語法進行了細微的修改, END_DATE「CASE WHEN END_DATE =' - 'THEN NULL ELSE to_date(:END_DATE,'DD-MM-YYYY') END」 –

相關問題