MYSQL LOAD DATA INFILE

时间:2011-01-18 11:29:19

标签: mysql null load-data-infile

我在mysql中使用LOAD DATA INFILE。在我的输入文件中,我有“x”字符,但我必须将其保存为数据库为NULL。我该怎么办?

2 个答案:

答案 0 :(得分:3)

load data infile... 
into table ...
fields terminated by...
lines terminated by ...
(
 my_field...
)
set 
my_field = if(my_field = 'x', null, my_field);

答案 1 :(得分:1)

load data infile... 
into table ...
fields terminated by...
lines terminated by ...
(
 @var...
)
set 
my_field = if(@var = 'x', null, @var);

感谢pekka