[英]How to return a result-set from second select statement in a procedure?
How can I return a result-set from a second select statement 如何从第二条选择语句返回结果集
I have the sample: 我有示例:
-- --------------------------------------------------------------------------------
-- Routine DDL
-- Note: comments before and after the routine body will not be stored by the server
-- --------------------------------------------------------------------------------
DELIMITER $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `getGender20`(in id INT)
BEGIN
DECLARE str VARCHAR(50);
select @str :=gender from memeber_info where id=id;
if (str = 'Male') then
select '12345' ;
end if;
select '123' ;
END
My procedure is retuning male
while I need it to return 123
. 我的程序正在调整male
而我需要返回123
。 How this can be achieved? 如何做到这一点?
You can do that without a variable by using case
您可以使用case
,而无需变量
select case when gender = 'Male'
then 12345
else 123
end as some_name
from memeber_info
where id=id;
In java you can get the next result set from the Statement
using the getMoreResults
function. 在Java中,您可以使用getMoreResults
函数从Statement
获取下一个结果集。 The method returns a boolean, which is true if more result sets are available. 该方法返回一个布尔值,如果有更多结果集可用,则为true。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.