2012-07-29 75 views
0

我怎样才能返回结果集从第二select语句如何从过程中的第二个select语句返回结果集?

我有样:

-- -------------------------------------------------------------------------------- 
-- 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 

我的程序重新调整male,而我需要它返回123。这可以如何实现?

回答

1

你可以做,没有一个变量使用case

select case when gender = 'Male' 
      then 12345 
      else 123 
     end as some_name 
from memeber_info 
where id=id; 
+0

感谢您的帮助,但我可以使用结果集中的第二个select查询输出 – user1047873 2012-07-29 19:21:14

+0

如果您使用[mysqli](http://php.net/manual/en/mysqli.multi-query.php),则可以使用。不知道其他API的。 – Vatev 2012-07-29 19:39:48

0

在java中,你可以得到下一个结果使用getMoreResults函数从Statement设置。该方法返回一个布尔值,如果有更多结果集可用,则返回true。

相关问题