我有一个表,其中有一varchar
列名为birthday
CREATE TABLE IF NOT EXISTS `test` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`birthday` varchar(30) COLLATE utf16_unicode_ci NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf16 COLLATE=utf16_unicode_ci AUTO_INCREMENT=5 ;
INSERT INTO `test` (`id`, `birthday`)
VALUES (1, '20041225'),
(2, '2004-12-25'),
(3, '19941225'),
(4, '19941201');
我尝试运行此查询:
SELECT str_to_date(birthday,"%Y%m%d")
FROM `test`
WHERE 1
但它总是返回具有空值的行。
如果我运行查询:
SELECT str_to_date('20141225',"%Y%m%d")
FROM `test`
WHERE 1
它会回来2014-12-25
那么我的查询有什么问题?