mysql游标select into导致游标提前结束解决办法

来源:互联网 发布:蚌埠学院网络 编辑:程序博客网 时间:2024/06/06 01:39

最近在mysql游标遍历中使用select into赋值时出现游标提前结束的问题,网上查资料发现是由于当select into赋值时若没有查询到数据则会导致游标提前退出;

解决方案:

在select into赋值之前加入判断查询结果是否存在,如:

if(EXISTS(select 1 from bs_area where id = (select county from k3_agency where id = custId))) THEN  #判断是否存在结果 存在则赋值
select id,name from bs_area where id = (select county from k3_agency where id = custId) INTO areaId,areaName;#复制语句
end if;

0 0
原创粉丝点击