返回函数中的计数 - Mysql

时间:2014-07-03 10:30:42

标签: mysql function

我有一个复杂的SQL,希望有一个我可以调用的函数,它返回行数。

我写道:

BEGIN
    declare thetotal INT;
    select count(id) AS thetotal from countries where id = countryid;
    RETURN thetotal;
END;

但它不会让我从选择中返回。

2 个答案:

答案 0 :(得分:1)

改为使用SELECT..INTO

BEGIN
    declare thetotal INT;
    select count(id) INTO thetotal from countries where id = countryid;
    RETURN thetotal;
END;

答案 1 :(得分:0)

BEGIN
declare thetotal INT;
select @thetotal =count(id)  from countries where id = countryid;
RETURN thetotal;
END;