USE test;
DELIMITER //
CREATE PROCEDURE pro8(OUT para1 VARCHAR(20))
BEGIN
DECLARE myid INT(11);
DECLARE title VARCHAR(100);
DECLARE i INT DEFAULT 0;
DECLARE str VARCHAR(60);
DECLARE len INT(2);
DECLARE num INT;
DECLARE cur CURSOR FOR SELECT id FROM test.`info`;
SELECT COUNT(*) INTO num FROM test.`info`;
SET str='';
OPEN cur;
WHILE i<num DO
FETCH cur INTO myid;
SET str = CONCAT(str,myid,',');
SET i=i+1;
END WHILE;
SELECT LENGTH(str) INTO len;
SELECT SUBSTR(str,1,len-1) INTO para1;
CLOSE cur;
END//
DELIMITER ;
CALL pro8(@a);
SELECT @a;
http://blog.csdn.net/baixiaoshi/article/details/40112265