我想从另一个表的字段中更新一个日期字段,如下所示:
UPDATE table1
left join table2 on table1.key = table2.key
set table1.old_date = STR_TO_DATE(table2.string_date,'%Y%m%d %T');
SELECT table1.old_date, table2.string_date, STR_TO_DATE(string_date,'%Y%m%d')) as "new_dob"
left join table2 on table1.key = table2.key我的old_date是一个日期时间字段,我的string_date是一个格式为'YYYYMMDD‘的字符串日期。当我选择我的日期时,它的格式很好,但是当我尝试更新它时,它失败并返回错误:
Data Truncation error occurred on a write of column 0Data was 0 bytes long and 0 bytes were transferred.我认为这是一个日期格式的问题,但我找不到一个真正的解决方案(我尝试了几个)基于这个错误在这里的社区。
谢谢
编辑:我在这里添加了一些关于我的数据库的信息:
ColumnIndex getColumnName getColumnTypeName getPrecision getScale isNullable getTableName getSchemaName getCatalogName getColumnClassName getColumnDisplaySize getColumnLabel getColumnType isAutoIncrement isCaseSensitive isCurrency isDefinitelyWritable isReadOnly isSearchable isSigned isWritable
1 string_date VARCHAR 8 0 1 dump_external_customer my_db java.lang.String 8 string_date 12 false false false true false true false true
2 old_date DATETIME 19 0 0 customer my_db java.sql.Timestamp 19 old_date 93 false false false true false true false true19750921
1970-08-17 00:00:00
我的转换日期1975-09-21
发布于 2016-03-04 21:02:10
UPDATE table1 left join table2 on table1.key = table2.key set table1.old_date = date_format(STR_TO_DATE(table2.string_date,'%Y%m%d'),'%Y-%m-%d');
https://stackoverflow.com/questions/35796115
复制相似问题