How to use decode in sql-loader?

非 Y 不嫁゛ 提交于 2019-12-11 18:36:07

问题


I use sqlldr to import CSV files and I have some problem with date multiple formats.

Dates inside the CSV file are DD/MM/YYYY and if there is no date it is a single dot


CSV file


DATE_COLUMN;OTHER_COLUMN
01/01/2013;other column content 1
.;other column content 2

My .ctl file for sqlldr


LOAD DATA
INFILE '/path/to/my/file.csv'
REPLACE INTO TABLE table_to_fill
FIELDS TERMINATED BY ';'
(
COLUMNDATE "decode(:COLUMNDATE ,NULL,'.', to_date(:COLUMNDATE ,'DD/MM/YYYY'))",
OTHER_COLUMN
)

The import is working when I use :

decode(:COLUMNDATE ,NULL,'.'))

or

to_date(:COLUMNDATE ,'DD/MM/YYYY')

But not when I try to combine both...

Here is the error log :

Record 1: Rejected - Error on table table_to_fill, column COLUMNDATE.
ORA-01858: a non-numeric character was found where a numeric was expected

How can I combine these, please ?

I thought that the last parameter of the "decode" function was for the default value of the column, am I wrong ?


回答1:


SQL Loader's "regular" syntax should be enough here. Try this:

LOAD DATA
INFILE '/path/to/my/file.csv'
REPLACE INTO TABLE table_to_fill
FIELDS TERMINATED BY ';'
(
  COLUMNDATE DATE(7) "DD/MM/YYYY" NULLIF COLUMNDATE = "."
  OTHER_COLUMN
)


来源:https://stackoverflow.com/questions/18130689/how-to-use-decode-in-sql-loader

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!