I am learning about sprocs with Mysql, and the central query does not "compile", I get a syntax warning starting at "count(language) into ".
I'm sending in one var, and expecting 2 back, a string of all languages, and an int count.
drop procedure if exists langcnt;
delimiter &&
create procedure langcnt(
IN ctry char(20)
, OUT langs varchar(100)
, OUT cnt int(3)
)
begin
select group_concat(language) into langs
, count(language) into cnt
from countrylanguage where countrycode = ctry;
end &&
delimiter ;
call langcnt('fra', @langs, @cnt);
select @langs, @cnt;
When isolated, the following does work as expected:
select group_concat(language) as langs,
count(language) as cnt
from countrylanguage where countrycode = 'fra';
Can anyone enlighten me, what rule have I broken?
EDIT: SB:
select group_concat(language)
, count(language) into langs, cnt
from countrylanguage where countrycode = ctry;
FTW, cheers @Bill Karwin
SELECT
does not take anINTO
clause after each column.The
INTO
clause goes at the end of the select-list, where you can name multiple variables, in the same order as the columns of the select-list.https://dev.mysql.com/doc/refman/5.6/en/select-into.html says: