MYSQL函数创建语法错误

时间:2017-07-06 12:05:17

标签: mysql mysql-function

我正在尝试创建一个查询以返回2天之间的工作日数,但在尝试创建函数时,它会给出以下错误。

第1行的错误1064(42000):您的SQL语法出错;检查与MySQL服务器版本对应的手册,以便在第5行附近使用正确的语法

请帮助我,这是我写的第一个MySQL函数。目前,我无法弄清楚我做错了什么,也有任何改进的余地让我知道。

CREATE FUNCTION getNumOfDays (order_num_input INT)
RETURNS INT
DETERMINISTIC
BEGIN
  DECLARE total_days INT;

  SET total_days = 0;

  /* To get the id, end_date, actual_end_date and getting num of days between start date and end date of the table based on provided order number */
  SELECT case when datediff(end_date, start_date) = 0 then 1 else datediff(end_date, start_date) end INTO total_days
    FROM order
    WHERE order_num = order_num_input;


  RETURN total_days;
END

0 个答案:

没有答案