CREATE FUNCTION `ge3`(st int,type int) RETURNS varchar(200) CHARSET utf8
begin
declare result varchar(200) default '' ;
declare i int;
set result=0;
set i = 1;
loop_example : loop
if type=1 then
set result = concat('222');
else
set result=concat('121323213');
end if;
set i = i + 1;
if i > st then
leave loop_example;
end if;
end loop;
return (concat((select id from table_name where id=1),"|",result));
end;
调用 select ge3(1,2);