请大神指点一下我这个存储过程,感谢

qq_30635781 2017-09-19 06:43:33

我的需求是把上面字段里的 4: XX 5:XX 取出来

我利用游标写的存储过程如下,麻烦大神帮忙看看,调用的时候报错
Error Code : 1172
Result consisted of more than one row
DELIMITER $$



CREATE PROCEDURE `p_fourfive`(out _four varchar(10), out _five varchar(10))
SQL SECURITY INVOKER
BEGIN
declare _Fou int(10);
declare _Fiv int(10);
declare done int default false;

#得到4和5的位置
declare cur_account cursor for select LOCATE(',4:',packet)+1 ,LOCATE(',5:',packet)+1 from t_u_playerinfo;
declare continue handler for not found set done = true;

open cur_account;
read_loop: LOOP

FETCH cur_account into _Fou,_Fiv;
if done then
leave read_loop;
end if;


if _Four = 0 then
set _Four = 0;
else
select substring_index(substring(packet,_Fou,6),',',1) into _four from t_u_playerinfo;
end if;
if _Five = 0 then
set _Five = 0;
else
select substring_index(substring(packet,_Fiv,6),',',1) into _five from t_u_playerinfo;
end if;
end LOOP;
CLOSE cur_account;

END$$

DELIMITER ;
...全文
353 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
little_how 2017-09-25
  • 打赏
  • 举报
回复
在你的变量里面加一个你这个表的主键 DELIMITER $$ CREATE PROCEDURE `p_fourfive`(out _four varchar(10), out _five varchar(10)) SQL SECURITY INVOKER BEGIN declare _Fou int(10); declare _Fiv int(10); declare _id int; declare done int default false; #得到4和5的位置 declare cur_account cursor for select your_primary_key_name,LOCATE(',4:',packet)+1 ,LOCATE(',5:',packet)+1 from t_u_playerinfo; declare continue handler for not found set done = true; open cur_account; read_loop: LOOP FETCH cur_account into _id,_Fou,_Fiv; if done then leave read_loop; end if; if _Four = 0 then set _Four = 0; else select substring_index(substring(packet,_Fou,6),',',1) into _four from t_u_playerinfo where your_primary_key=_id; end if; if _Five = 0 then set _Five = 0; else select substring_index(substring(packet,_Fiv,6),',',1) into _five from t_u_playerinfo where your_primary_key=_id; end if; end LOOP; CLOSE cur_account; END$$ DELIMITER ;
zjcxc 2017-09-20
  • 打赏
  • 举报
回复
 select  substring_index(substring(packet,_Fou,6),',',1) into _four from t_u_playerinfo; ----------------------- 这个不是应该查当前行的记录么? 你这个没条件啊
qq_30635781 2017-09-20
  • 打赏
  • 举报
回复
引用 4 楼 zjcxc 的回复:
 select  substring_index(substring(packet,_Fou,6),',',1) into _four from t_u_playerinfo; ----------------------- 这个不是应该查当前行的记录么? 你这个没条件啊
我的本意是用上面的游标循环读取到结果,然后放到 _Four这个变量里面,循环查询出结果,请指点一下
qq_30635781 2017-09-20
  • 打赏
  • 举报
回复
引用 2 楼 ACMAIN_CHM 的回复:
引用
Error Code : 1172 Result consisted of more than one row
检查SELECT INTO语句,返回了多行。
恩,这个我知道,但是不知道该怎么修改,麻烦指点一下,谢谢版主
ACMAIN_CHM 2017-09-20
  • 打赏
  • 举报
回复
引用
Error Code : 1172 Result consisted of more than one row
检查SELECT INTO语句,返回了多行。
qq_30635781 2017-09-20
  • 打赏
  • 举报
回复
请问有人吗????
ACMAIN_CHM 2017-09-20
  • 打赏
  • 举报
回复
select substring_index(substring(packet,_Fou,6),',',1) into _four from t_u_playerinfo; 加上WHERE

56,687

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧