0
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

上面的 SQL 代码显示存在语法错误。

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

任何想法如何解决它?

4

2 回答 2

2

;语法错误,您在 SELECT 语句之后错过-

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
于 2013-04-08T09:37:19.543 回答
0

试试这个

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

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

        END
于 2013-04-08T09:39:10.140 回答