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;
但是我在代码中 查询,却可以正确显示结果,这是什么原因
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变量重名了。删了就行了,如果有需要,修改成别的名字。
谢谢,已经解决