MySQL中自定义函数总是报错?

测试从一个表中提取出不重复得名字个数,建立的函数执行一直报错,求解
函数:

create function nameNum() returns int
begin
    declare a int;
    select count(distinct name) from score into a;
    return a;
end;

报错:/* SQL错误(1064):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 a' at line 1 */

我这里复制直接执行成功了,可能要看下是不是你装的mysql是不是有问题,或者中英文写错了,或者设置编码有问题。