我使用mysql进程来选择结果。像
delimiter //
DROP procedure IF EXISTS prd_action;
create procedure prd_action()
BEGIN
DECLARE v_userid int;
DECLARE done INT DEFAULT 0;
DECLARE cur CURSOR FOR SELECT distinct user_id from friends where user_id > 30;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = 1;
OPEN cur;
REPEAT
FETCH cur into v_userid;
if not done then
select * from friends where user_id = v_usetid
end if;
UNTIL done END REPEAT;
CLOSE cur;
END//
delimiter
结果集1,结果集2,。。。,resultset10它们是结果集,但我希望它们组合成一个结果集。
试试这个:
delimiter //
DROP procedure IF EXISTS prd_action;
create procedure prd_action()
BEGIN
select * from friends f
where user_id > 30;
END//
delimiter ;
-----编辑----
如果必须使用v_usetid参数而不是30,请尝试以下代码:
create procedure prd_action(v_userid int)
BEGIN
select * from friends f
where user_id > v_userid;
END/
演示-->http://www.sqlfiddle.com/#!2/f717d/3