Home  >  Q&A  >  body text

php - mysql 创建存储过程中用到循环,怎么通过select返回结果集

CREATE procedure ceshi(in Str varchar(2048),in SplitChar varchar(50))
begin
declare ind int;
declare unit varchar(128);
declare inext int;
declare len int;
declare i int;
set ind=1;
set i=1;
set len=length(Str);
while ind<=len do
begin
set inext=instr(Str,SplitChar);
if inext=0 then set inext=len+1; end if;
if inext>ind then
begin
set unit=ltrim(rtrim(substring(Str,1,inext-1)));
if unit<>'' then
begin
select unit as Value,i as vindex; //这里的select每循环一次,值就不一样,我想让他作为结果集返 //回应该怎么做
set Str=substring(Str,inext+1);
set i=i+1;
select Str,ind,inext,len,unit;
end;
end if;
end;
end if;
end;
set ind=inext+1;
end while;
end;

ringa_leeringa_lee2641 days ago599

reply all(1)I'll reply

  • PHP中文网

    PHP中文网2017-04-10 17:38:17

    把值放入数组?

    reply
    0
  • Cancelreply