DELIMITER //
CREATE FUNCTION BusinessDays(d1 DATE,d2 DATE)
RETURNS INT
READS SQL DATA DETERMINISTIC
BEGIN
DECLARE out_date DATE;
DECLARE fromdate DATE;
DECLARE todtae DATE;
DECLARE minus INT;
DECLARE result INT;
SET minus = 0;
SET result = DATEDIFF(todate , fromdate);
WHILE (fromdate <= todate) DO
IF (fromdate = 1 OR fromdate = 7) THEN
SET minus = (minus)+1;
END IF;
SET fromdate = fromdate + INTERVAL 1 DAY;
END WHILE;
RETURN result - minus;
END;
END //
DELIMITER ;
错误代码:1064您的SQL语法出错;检查与MySQL服务器版本对应的手册,以便在第20行的“END”附近使用正确的语法