我有一张表,其中有一个名为birthday
的varchar
列。
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
那么我的查询有什么问题吗?