使用十进制值加载数据本地infile

时间:2014-02-11 08:57:35

标签: mysql csv

我为客户创建了csv文件的导入程序,而我遇到的问题是我在文件中得到了十进制值的截断值,例如:

in .csv file price is 12,23
and in database it is saved as 12.

我检查了字段,它们被设置为十进制(10,2)所以这不应该是正常的。我加载文件的代码是:

LOAD DATA LOCAL INFILE "U:/v7/root/file/docimport/3/87/article.csv" 
INTO TABLE im_artikel 
CHARACTER SET latin1 FIELDS TERMINATED BY ";" IGNORE 1 LINES 
(article,price,grossprice);
show WARNINGS;

我收到错误:

1265 Data truncated for column 'price' at row 1
1265 Data truncated for column 'grossprice' at row 1

.Csv文件如下所示:

Shoes;40,00;21,46

我可以将所有字段更改为varchar而不是没有问题,但我认为这不是解决方案。

1 个答案:

答案 0 :(得分:7)

请试试这个:

LOAD DATA LOCAL INFILE "U:/v7/root/file/docimport/3/87/article.csv" 
INTO TABLE im_artikel 
CHARACTER SET latin1 FIELDS TERMINATED BY ";" IGNORE 1 LINES 
(article,@p,@gp)
SET price = REPLACE(@p, ',', '.'), grossprice = REPLACE(@gp, ',', '.');