1
我想加載數據到MySQL表中,並且所有的時間戳(日期時間字段類型)都被加載爲空。我嘗試加載的一個示例值是"2002-04-26 19:31:15.200000000"
,並且我已指定格式爲'%Y-%c-%d %H:%i:%s.%f'
(下面的語句)。MYSQL加載數據時間戳格式
由於null正在加載我做了一個假設,我有格式不正確,並導致null被加載。我應該指定什麼樣的正確格式?
set DateAdded = STR_TO_DATE(@DateAdded,'%Y-%c-%d %H:%i:%s.%f')
完整LOAD INFILE
聲明:
LOAD DATA INFILE 'CANDIDATES.txt' INTO TABLE dbo.CANDIDATE
FIELDS TERMINATED BY '|'
ignore 1 lines
(ResumeKey,Address1,Address2,City,Candidate_Type,Candidate_Type_Changed_UserID,State,Country,@DateAdded,@DateModified,Degree,Email,FirstName,GPA,GradYear,HomePhone,JobTitle,LastName,Locale,Major,MiddleName,OrgName,OtherPhone,SchoolName,Zip,Active_Flag,SecureCandidate_Flag,CandidateStackingField,CellPhone,Homepage,FaxNumber,BRUID)
set
DateAdded = STR_TO_DATE(@DateAdded,'%Y-%c-%d %H:%i:%s.%f'),
DateModified = STR_TO_DATE(@DateModified,'%Y-%c-%e %H:%i:%s.%f');
似乎按預期工作。我從SELECT STR_TO_DATE('2002-04-26 19:31:15.200000000','%Y-%c-%d%H:%i:%s。%f')得到了正確的值;'你的'LOAD INFILE'聲明的其餘部分看起來像?可能有另一個錯誤。 –
注意:'%m'可能比'%c'更適合零填充的月份,但這應該可以工作。 –
當然,聲明的其餘部分:LOAD DATA INFILE'CANDIDATES.txt'INTO TABLE dbo.CANDIDATE FIELDS TERMINATED BY'|'忽略1行 (ResumeKey,Address1,Address2,City,Candidate_Type,Candidate_Type_Changed_UserID,State,Country,@ DateAdded,@ DateModified,Degree,Email,FirstName,GPA,GradYear,HomePhone,JobTitle,LastName,Locale,Major,MiddleName, OrgName,OtherPhone,SchoolName,Zip,Active_Flag,SecureCandidate_Flag,CandidateStackingField,CellPhone,Homepage,FaxNumber,BRUID) set DateAdded = STR_TO_DATE(@DateAdded,'%Y-%c-%d%H:%i:%s。% f'), DateModified = STR_TO_DATE(@DateModified,'%Y-%c-%e%H:%i:%s。%f') ; – Doug