DELIMITER $$;
DROP PROCEDURE IF EXISTS `test`.`xybtest`$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `xybtest`(IN tid int,out tchar varchar(50))
BEGIN
declare maxid int;
declare isOk boolean;
declare _test_id int;
declare _test_info varchar(500);
declare cur cursor for select test_id,test_info from test1;
declare continue handler for NOT FOUND set isOk = true;
select max(test_id) into maxid from test1;
if maxid = tid then
insert into test1 values (maxid+1,'cccccc');
end if;
open cur;
fetchLoop:Loop
if isOk then
leave fetchLoop;
else
fetch cur into _test_id,_test_info;
if _test_id is not null then
update test1 set test_info = concat(test_info,_test_info) where test_id = _test_id;
end if;
end if;
end Loop;
close cur;
set tchar = 'gggggggggg';
END$$
DELIMITER ;$$