我似乎无法正常工作,这总是一个不同的错误。在这一点上,我们非常感谢任何建议。。。
CREATE DEFINER=`db`@`localhost` FUNCTION `output_date`(in_date DATE) RETURNS DATE
READS SQL DATA
BEGIN
DECLARE date_format_index INT;
DECLARE date_format_string VARCHAR;
SELECT s.output_date_format INTO date_format_index FROM config s
SET date_format_string = ( CASE date_format_index WHEN 2 THEN '%d-%m-%Y' WHEN 3 THEN '%m-%d-%Y' ELSE '%Y-%m-%d' END );
RETURN in_date
END
我在尝试处理这个函数时使用了DELIMITER$$。
当前错误为。。。
Error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '; SELECT s.output_date_format INTO date_format_index FROM system_config s SET d'
我的环境是最新版本的MyEclipse。我的MySQL版本是5.2。
您缺少一些分号,并且varchar有问题,请尝试以下操作:
DELIMITER $$
CREATE DEFINER=`db`@`localhost` FUNCTION `output_date`(in_date DATE) RETURNS DATE
READS SQL DATA
BEGIN
DECLARE date_format_index INT;
DECLARE date_format_string VARCHAR(100); -- obviously change the size
SELECT s.output_date_format INTO date_format_index FROM config s;
SET date_format_string = ( CASE date_format_index WHEN 2 THEN '%d-%m-%Y' WHEN 3 THEN '%m-%d-%Y' ELSE '%Y-%m-%d' END );
RETURN in_date;
END
$$
DELIMITER ;
它在我的箱子上跑。