3

我无法加载具有所谓有效日期时间格式的文件。例如,加载文件中的一行如下所示:4,0,'2012-08-09 22:34:28','2012-08-09 22:34:28'

相同的格式适用于插入语句。加载时这不是有效的日期时间格式吗?在任何情况下我们都必须指定默认格式吗?我应该投吗?

4

2 回答 2

0

在您的LOAD DATA INFILE声明中添加

OPTIONALLY ENCLOSED BY "'"

语法见手册

LOAD DATA [LOW_PRIORITY | CONCURRENT] [LOCAL] INFILE 'file_name'
    [REPLACE | IGNORE]
    INTO TABLE tbl_name
    [CHARACTER SET charset_name]
    [{FIELDS | COLUMNS}
        [TERMINATED BY 'string']
        [[OPTIONALLY] ENCLOSED BY 'char']
        [ESCAPED BY 'char']
    ]
    [LINES
        [STARTING BY 'string']
        [TERMINATED BY 'string']
    ]
    [IGNORE number LINES]
    [(col_name_or_user_var,...)]
    [SET col_name = expr,...]
于 2015-04-26T22:41:25.627 回答
0

OP回答:

啊!没关系。加载文件时,日期时间不会在其周围加上引号。因此,该行应该是 4,0,2012-08-09 22:34:28, 2012-08-09 22:34:28

(从“未答复”中删除)

于 2015-04-26T22:36:13.170 回答