create procedure sp_split(str varchar(40), del varchar(1))
begin
declare idx int; //olvido declara int y de frente inicializo
declare idxOld int;//olvido declara int y de frente inicializo
declare subs varchar(50);//olvido declarar subs y de frente inicializo
set idx := 1;
//set idxOld := idx;
set token:='';
set str := trim(str);
set idx := instr(str,del);
while(idx > 0) //error poner 0 porque las cadenas comienzan con 1 y devuelve 0 si no encuentra
begin
//set token := substring(str,idxOld + 1,idx-idxOld); error
set token := SUBSTRING(str,1,idx - 1);
insert into tblTemp(token);
//set idx := idx + 1;
//set str := SUBSTRING(str,idx,LENGTH(str) - idx + 1);
set str := SUBSTRING(str,idx + 1,LENGTH(str) - idx);
//set idxOld := idx;
set idx: = SUBSTR(str,idx);
end
IF(LENGTH(str) > 0)
BEGIN
insert into tablTemp(str);
END
end
$$
delimiter $$
create procedure split(s varchar(100), del varchar(1))
begin
declare start int;
declare end int;
set start = 1;
set endp1 = locate(s,del,start) ;
while(endp1 > 0)
begin
insert int tbl(substring(s,start,endp1 - 1))
start = endp1 + 1;
end1 := locate(s,del,start);
end
if(start <= length(s))
begin
substring(s,start,length(s) - start + 1)
end
end
while(endp1 > 0)
begin
insert int tbl(substring(s,start,endp1 - 1))
start = endp1 + 1;
end1 := locate(s,del,start);
end
if(start <= length(s))
begin
substring(s,start,length(s) - start + 1)
end
$$
create temporary table temp_table(
datasplit varchar(100)
);
No hay comentarios:
Publicar un comentario