我有一个复杂的SQL,希望有一个我可以调用的函数,它返回行数。
我写道:
BEGIN
declare thetotal INT;
select count(id) AS thetotal from countries where id = countryid;
RETURN thetotal;
END;
但它不会让我从选择中返回。
答案 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;