[英]Change the date format in a csv .txt file before importing using mysqlbulkloader
对于将来寻找答案的任何人,最好的方法是使用加载数据本地 infile 选项,您需要在其中调用特定列并使用 @ 符号指定要预处理的列。 就像下面的例子。 您可能还需要更新客户端和服务器端设置以允许加载数据选项工作。
在我下面的代码示例中,我想将 createdate 字段从 m/d/y 格式更改为 yyyy-mm-dd 的 mysql 格式
LOAD DATA local INFILE 'C:/Users/username/Documents/SAP/SAP GUI/QNs.txt'
IGNORE
INTO TABLE tbl_quality_notification
FIELDS TERMINATED BY '|'
LINES starting by '|'
TERMINATED BY '\r\n'
IGNORE 6 ROWS
(@CreateDate,
NotificationNumber,
ItemNumber,
WorkOrder,
MaterialNumber,
MaterialDescription,
Disposition,
DeptResponsible,
OperationCaused,
DefQtyInt,
DefQtyExt,
TotalQty,
WcOpFoundAt,
OpDescription,
DefectLocation,
ProblemType,
ProblemDescription,
CauseCode,
CauseDescription,
RootCause,
CorrectiveAction)
SET CreateDate = STR_TO_DATE(@CreateDate, '%m/%d/%Y')
感谢 GMB,加载本地 infile 似乎是正确的解决方案。 我将发布一个新线程来解决无效字符串问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.