MySQL加载CSV文件,但没有双引号?

时间:2018-10-23 04:46:44

标签: mysql csv load quotes

我正在使用MySQL加载CSV文件,但是字符串列没有引号,所以我只得到该值的第一个字母。

public static String convertToRupiah(String priceBeforeConverted){

    //manual setting separator, because currently RUPIAH is NOT supported
    DecimalFormat formatter = (DecimalFormat) DecimalFormat.getCurrencyInstance();
    DecimalFormatSymbols formatRupiah = new DecimalFormatSymbols();
    formatRupiah.setCurrencySymbol("Rp ");
    formatRupiah.setMonetaryDecimalSeparator(',');
    formatRupiah.setGroupingSeparator('.');
    formatter.setDecimalFormatSymbols(formatRupiah);

    Double price = StringFormatter.isNullOrEmpty(priceBeforeConverted) ? 0.00 : Double.valueOf(priceBeforeConverted) ;
    String conversionResult = formatter.format(price);

    if(conversionResult.endsWith(",00"))
        conversionResult = conversionResult.substring(0, conversionResult.length()-3);

    return conversionResult;
}

在这里使用代码后,我得到了:

1,Toyota Park,Bridgeview,IL,0
2,Columbus Crew Stadium,Columbus,OH,0
3,RFK Stadium,Washington,DC,0

我有这张桌子:

LOAD DATA LOCAL INFILE 'C:\\Users\\tank\\Desktop\\test.csv'
INTO TABLE test
FIELDS TERMINATED BY ',' 
LINES TERMINATED BY '\n'
IGNORE 0 ROWS;

1 个答案:

答案 0 :(得分:0)

您应该使用以下附件:

right()
相关问题