DELIMITER //
CREATE FUNCTION `f_media`(
`f_Date` DATE,
`f_mediaexposure` VARCHAR(30),
`f_sentiment` VARCHAR(30)
)
RETURNS INT(10)
BEGIN
DECLARE v_result INT;
SELECT v_result := COUNT(*)
FROM media_1
WHERE Mediumcat LIKE '%f_mediaexposure%' AND
Date = f_Date AND
sentiment = f_sentiment;
RETURN v_result
END;//
DELIMITER ;
这对我不起作用。谁知道我做错了什么?只是SQL的初学者。已经尝试过分界符,但仍然没有运气。
1064 - Er is is fout in de gebruikte syntax bij':= COUNT(*)FROM media_1 WHERE Mediumcat LIKE'%f_mediaexposure%'AN'in regel 10
答案 0 :(得分:0)
我的猜测是你需要:
delimiter
:=
此外,您应该更清楚地命名您正在使用的参数并使用分号:
DELIMITER //
CREATE FUNCTION `f_media`(
`f_Date` DATE,
`f_mediaexposure` VARCHAR(30),
`f_sentiment` VARCHAR(30)
)
RETURNS INT(10)
BEGIN
DECLARE v_result INT;
SELECT COUNT(*) INTO v_result
FROM media_1
WHERE Mediumcat LIKE '%f_mediaexposure%' AND
Date = f_Date AND
sentiment = f_sentiment;
RETURN v_result
END;//
DELIMITER ;