MySQL LOAD DATA INFILE with comma as decimal separator

前端 未结 2 1204
粉色の甜心
粉色の甜心 2020-12-11 19:29

How can I import a TSV file when the numbers use comma as a decimal separator?

LOAD DATA INFILE \'$filename\' INTO TABLE dados_meteo IGNORE 3 LINES 
($fields         


        
2条回答
  •  半阙折子戏
    2020-12-11 19:48

    If $field[0] is your numeric:

    LOAD DATA INFILE '$filename' INTO TABLE dados_meteo IGNORE 3 LINES 
    (@var1, $fields[1], $fields[2], $fields[3], $fields[4], $fields[5])
    SET POM='$pom', $field[0] = CONVERT(REPLACE(@var1,',', ''), DECIMAL(10));
    

    If more are numeric, simply repeat the pattern with a @var2, @var3, etc. You'll want to replace the DECIMAL(10) with whatever your field really is.

提交回复
热议问题