功能:
DELIMITER $$
DROP FUNCTION IF EXISTS `ToYear` $$
CREATE FUNCTION .`ToYear` (input varchar(47)) RETURNS year
BEGIN
RETURN year(str_to_date(@input,_utf8'%m/%d/%Y'));
END $$
DELIMITER ;
函数调用
SELECT ToYear('8/12/2013')
为什么我的函数在放入SELECT语句时返回NULL,它返回年份?
SELECT year(str_to_date('8/12/2013',_utf8'%m/%d/%Y'));
返回:2013
答案 0 :(得分:2)
DELIMITER $$
DROP FUNCTION IF EXISTS `ToYear` $$
CREATE FUNCTION `ToYear` (input char(10)) RETURNS year
BEGIN
RETURN year(str_to_date(input,_utf8'%m/%d/%Y'));
END $$
DELIMITER ;