beau8008
beau8008

Reputation: 49

Syntax error in a create function, MySQL

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

Answers (1)

potashin
potashin

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

Related Questions