我有一个格式如下的 csv 文件,
sth, sth, "100,000,000", sth, "200,000"
sth, sth, "200,000,000", sth, "500,000"
当我使用时
mysql> load data local infile "thefile.csv" into table mytable terminated by ',' enclosed by '"' lines terminater by '\r\n';
然后“100,000,000”、“500,000”等数字被截断。
请帮助我!
最佳答案
从 CSV 文件中删除空格:
sth,sth,"100,000,000",sth,"200,000"
sth,sth,"200,000,000",sth,"500,000"
并尝试使用此语句加载数据 -
LOAD DATA INFILE 'thefile.csv' INTO TABLE mytable
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\r\n'
(column1, column2, @var1, column4, @var2) -- specify actual field names
SET column3 = REPLACE(@var1, ',', ''), column5 = REPLACE(@var2, ',', ''); -- remove thousand separators
关于mySQL加载数据本地infile不正确的数字格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7901149/