The following stored function is returning: '#1172 - Result consisted of more than one row'
以下存储的函数返回:'#1172 - 结果由多行组成'
What am I doing wrong?
我究竟做错了什么?
It's a Stored function, with no params and expects an int to return.
它是一个存储函数,没有参数,并期望返回一个int。
BEGIN
DECLARE l_user_id INT;
sloop:LOOP
SELECT `user_id` INTO `l_user_id` FROM `users` WHERE `area_id` = 1;
INSERT INTO `user_function_hours` SET `function_hour_id` = 1, `user_id` = l_user_id;
INSERT INTO `user_function_hours` SET `function_hour_id` = 2, `user_id` = l_user_id;
INSERT INTO `user_function_hours` SET `function_hour_id` = 3, `user_id` = l_user_id;
INSERT INTO `user_function_hours` SET `function_hour_id` = 4, `user_id` = l_user_id;
INSERT INTO `user_function_hours` SET `function_hour_id` = 5, `user_id` = l_user_id;
END LOOP sloop;
RETURN 1;
END
1 个解决方案
#1
0
Yes, we will face this kind of errors in triggers.
是的,我们将在触发器中遇到这种错误。
Please check this query. It provides more than 1 records as result.
请检查此查询。它提供了超过1条记录。
SELECT `user_id` INTO `l_user_id` FROM `users` WHERE `area_id` = 1;
Please change this query as,
请将此查询更改为,
SELECT `user_id` INTO `l_user_id` FROM `users` WHERE `area_id` = 1 LIMIT 1;
So that, you can solve this error.
这样,你就可以解决这个错误。
#1
0
Yes, we will face this kind of errors in triggers.
是的,我们将在触发器中遇到这种错误。
Please check this query. It provides more than 1 records as result.
请检查此查询。它提供了超过1条记录。
SELECT `user_id` INTO `l_user_id` FROM `users` WHERE `area_id` = 1;
Please change this query as,
请将此查询更改为,
SELECT `user_id` INTO `l_user_id` FROM `users` WHERE `area_id` = 1 LIMIT 1;
So that, you can solve this error.
这样,你就可以解决这个错误。