简体   繁体   English

在 mysql 中调用过程时出错:错误代码:1222。使用的 SELECT 语句具有不同的列数

[英]error when I call procedure in mysql:Error Code: 1222. The used SELECT statements have a different number of columns

delimiter /
drop procedure if exists piez_vend;/
create procedure piez_vend (IN _piez varchar(20), out nvend int(11))
begin
SELECT numpieza, count(numvend) into nvend from preciosum where numpieza like _piez;
end
/
delimiter ;

call piez_vend('dd-0001-210',@nvend);

Sample data样本数据

 numpieza, numvend, preciounit, diassum, descuento
'a-1001-l', '1', '1.60', '3', '0'
'a-1001-l', '3', '3.00', '1', '0'
'c-400-z', '1', '7.80', '4', '5'
'c-400-z', '6', '6.50', '3', '0'
'dd-0001-210', '1', '300.00', '3', '15'
'dd-0001-210', '2', '310.00', '5', '12'
'dd-0001-210', '4', '287.00', '15', '10'
'm-0001-c', '1', '550.00', '3', '10'
'm-0001-c', '5', '570.00', '7', '15'
't-0002-at', '2', '25.80', '3', '0'
't-0002-at', '4', '27.00', '5', '7'

The error message is a little obtuse.错误信息有点迟钝。

The used SELECT statements have a different number of columns使用的 SELECT 语句具有不同的列数

It means this query这意味着这个查询

SELECT numpieza, count(numvend) into nvend from preci...

doesn't work because the SELECT mentions two columns.不起作用,因为SELECT提到了两列。 But you're using into to tell MySQL where to put the value of only one of the columns.但是您正在使用into告诉 MySQL 将其中一列的值放在哪里。 It doesn't know what to do with the other column.它不知道如何处理另一列。 Try this instead.试试这个。

SELECT count(numvend) into nvend from preci...

Pro tip Stored procedures are tricky to debug.专业提示存储过程很难调试。 It's helpful to try the queries in them before you wrap them in the procedure.在将它们包装在过程中之前尝试其中的查询是有帮助的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM