首页 新闻 会员 周边 捐助

mysql 存储过程问题,求大神指导!!!!!

0
悬赏园豆:10 [已解决问题] 解决于 2020-04-09 09:21

CREATE DEFINER=root@% PROCEDURE query_info(in p_id int,out p_info varchar(10))
BEGIN
declare p_type int(5);
declare p_info varchar(10);
select type into p_type from student where s_id = p_id;
case p_type
when 1 then select s_name into p_info from student where s_id = p_id;
when 2 then select score into p_info from student where s_id = p_id;
else select 'ERROR' INTO p_info;
end case;

END

CREATE DEFINER=root@% PROCEDURE query_info(in p_id int)
BEGIN
declare p_type int(5);
declare p_info varchar(10);
select type into p_type from student where s_id = p_id;
case p_type
when 1 then select s_name into p_info from student where s_id = p_id;
when 2 then select score into p_info from student where s_id = p_id;
else select 'ERROR' INTO p_info;
end case;
select p_info;

END

调用时 call query_info(04,@x); select @x; 查询结果为null;
但是我在代码中 查询,却可以正确显示结果,这是什么原因

渣&渣的主页 渣&渣 | 初学一级 | 园豆:43
提问于:2020-04-08 17:59
< >
分享
最佳答案
0
CREATE DEFINER=root@% PROCEDURE query_info(in p_id int,out p_info varchar(10))
BEGIN
declare p_type int(5);

declare p_info varchar(10);

select type into p_type from student where s_id = p_id;
case p_type
when 1 then select s_name into p_info from student where s_id = p_id;
when 2 then select score into p_info from student where s_id = p_id;
else select 'ERROR' INTO p_info;
end case;

END

你这里声明了一个变量和out变量重名了。删了就行了,如果有需要,修改成别的名字。

收获园豆:10
。淑女范erり | 小虾三级 |园豆:961 | 2020-04-08 20:15

谢谢,已经解决

渣&渣 | 园豆:43 (初学一级) | 2020-04-09 09:21
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册