报错:Result consisted of more than one row

shihengli2010 shihengli2010 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
写了一个函数:
参数 : `product_type` int,`app_id` bigint
返回: varchar(64)

BEGIN
#Routine body goes here...
declare typeName varchar(64);
select name into typeName from t_b_product_type where product_type = `product_type` and app_id = `app_id` ;
RETURN typeName;
END

报错:Result consisted of more than one row 。我看了下测试数据,只有一条符合上面的查询条件,不可能有多条记录。

修改为:
在select into 语句末尾添加 limit 1. 就能正常执行

或者给表添加别名,也能得到正确结果,
BEGIN
#Routine body goes here...
declare typeName varchar(64);
select name into typeName from t_b_product_type as a where a. product_type = `product_type` and a.app_id = `app_id` ;
RETURN typeName;
END

请教各位,这是什么情况。
...全文

相关推荐

评论 3
收藏 已收藏
分享
返回顶部
shihengli2010
MySQL 57,062 成员 56,759 内容