我正在使用 Mysql 学习存储过程,但中央查询没有“编译”,我收到从“count(language) into”开始的语法警告。
我正在发送一个 var,并期待返回 2 个、所有语言的字符串和一个 int 计数。
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;
隔离后,以下内容会按预期工作:
select group_concat(language) as langs,
count(language) as cnt
from countrylanguage where countrycode = 'fra';
谁能赐教,我违反了什么规则?
编辑:某人:
select group_concat(language)
, count(language) into langs, cnt
from countrylanguage where countrycode = ctry;
FTW,为@Bill Karwin 干杯
最佳答案
SELECT
不会在每一列之后使用 INTO
子句。
INTO
子句位于选择列表的末尾,您可以在其中命名多个变量,其顺序与选择列表的列相同。
select group_concat(language)
, count(language) into langs, cnt
from countrylanguage where countrycode = ctry;
https://dev.mysql.com/doc/refman/5.6/en/select-into.html说:
The
SELECT
syntax description (see Section 13.2.9, “SELECT Syntax”) shows theINTO
clause near the end of the statement. It is also possible to useINTO
immediately following the select_expr list.
关于mysql - 使用两个 OUT 变量的 Sproc 无法编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25753187/