Reputation: 49
So, below is the function i'm writing(in MySQL) and I get a syntax error at the last "RETURN" line (RETURN d_count). I'm sure it's some simple thing, but I can't figure it out. Thanks!
DELIMITER $$
CREATE FUNCTION dept_count (dept_name VARCHAR(20))
RETURNS INT DETERMINISTIC
BEGIN
DECLARE d_count INT;
SELECT COUNT(*) into d_count
FROM instructor
WHERE instructor.dept_name=dept_name
RETURN d_count;
END $$
Upvotes: 0
Views: 767
Reputation: 44581
You should separate SELECT
and RETURN
with semicolon ;
:
DELIMITER $$
CREATE FUNCTION dept_count (dept_name VARCHAR(20))
RETURNS INT DETERMINISTIC
BEGIN
DECLARE d_count INT;
SELECT COUNT(*) into d_count
FROM instructor
WHERE instructor.dept_name=dept_name;
RETURN d_count;
END $$
Upvotes: 2