Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.
CREATE FUNCTION count(name varchar(20))
        RETURNS integer
        BEGIN
        DECLARE d_count integer;
                select count(*) into d_count
                from ins
                where ins.name = name
        RETURN d_count;
        END

the SQL code above show there is a syntax error.

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'RETURN (d_count); END' at line 8

Any ideas how to fix it?

share|improve this question
    
What's the error? –  JMK Apr 8 '13 at 9:36
    
missing ; after select count(*) into d_count from ins where ins.name = name –  Satya Apr 8 '13 at 9:36
    
So... add that semicolon –  fedorqui Apr 8 '13 at 9:37
    
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'RETURN (d_count); END' at line 8 –  Froker Apr 8 '13 at 9:37
add comment

closed as too localized by fthiella, Jocelyn, Branko Dimitrijevic, Steven Penny, GoZoner Apr 9 '13 at 2:06

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

2 Answers

up vote 2 down vote accepted

Syntax error, you miss ; after the SELECT statement -

CREATE FUNCTION count (name varchar(20))
RETURNS integer
BEGIN
  DECLARE d_count integer;
  SELECT COUNT(*) INTO d_count FROM ins WHERE ins.name = NAME;
  RETURN d_count;
END
share|improve this answer
add comment

Try this

CREATE FUNCTION count(@name varchar(20))
        RETURNS integer
        BEGIN

        RETURN( select count(*) 
                from ins
                where ins.name = @name);

        END
share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.