有没有sql转化的语法。在网上找了好多,也没试出结果。请教大牛...
2 个解决方案
#1
那是在一起的字符串 ,必须拆分后 才行
#2
不知道是不是这个意思
创建存储过程
处理字符串:
读取结果:
结果:
![[mysql数据库] 查询结果为数组,怎样切割成字符串,再进行查询 [mysql数据库] 查询结果为数组,怎样切割成字符串,再进行查询](https://image.shishitao.com:8440/aHR0cHM6Ly93d3cuaXRkYWFuLmNvbS9nby9hSFIwY0hNNkx5OXBiV2N0WW1KekxtTnpaRzR1Ym1WMEwzVndiRzloWkM4eU1ERTNNREl2TWpndk1UUTRPREkyTnpJNU5GOHpPVGs0TlRjdWFuQm4%3D.jpg?w=700&webp=1)
创建存储过程
drop PROCEDURE if exists procedure_split;
CREATE PROCEDURE `procedure_split`(
inputstring varchar(1000),
delim char(1)
)
begin
declare strlen int DEFAULT length(inputstring);
declare last_index int DEFAULT 0;
declare cur_index int DEFAULT 1;
declare cur_char VARCHAR(200);
declare len int;
drop temporary table if exists splittable;
create TEMPORARY table splittable(
value VARCHAR(20)
) ;
WHILE(cur_index<=strlen) DO
begin
if substring(inputstring from cur_index for 1)=delim or cur_index=strlen then
set len=cur_index-last_index-1;
if cur_index=strlen then
set len=len+1;
end if;
insert into splittable(`value`)values(substring(inputstring from (last_index+1) for len));
set last_index=cur_index;
end if;
set cur_index=cur_index+1;
END;
end while;
end ;
处理字符串:
call PROCEDURE_split('1,2,3',',');
读取结果:
select * from splittable;
结果:
![[mysql数据库] 查询结果为数组,怎样切割成字符串,再进行查询 [mysql数据库] 查询结果为数组,怎样切割成字符串,再进行查询](https://image.shishitao.com:8440/aHR0cHM6Ly93d3cuaXRkYWFuLmNvbS9nby9hSFIwY0hNNkx5OXBiV2N0WW1KekxtTnpaRzR1Ym1WMEwzVndiRzloWkM4eU1ERTNNREl2TWpndk1UUTRPREkyTnpJNU5GOHpPVGs0TlRjdWFuQm4%3D.jpg?w=700&webp=1)
#1
那是在一起的字符串 ,必须拆分后 才行
#2
不知道是不是这个意思
创建存储过程
处理字符串:
读取结果:
结果:
![[mysql数据库] 查询结果为数组,怎样切割成字符串,再进行查询 [mysql数据库] 查询结果为数组,怎样切割成字符串,再进行查询](https://image.shishitao.com:8440/aHR0cHM6Ly93d3cuaXRkYWFuLmNvbS9nby9hSFIwY0hNNkx5OXBiV2N0WW1KekxtTnpaRzR1Ym1WMEwzVndiRzloWkM4eU1ERTNNREl2TWpndk1UUTRPREkyTnpJNU5GOHpPVGs0TlRjdWFuQm4%3D.jpg?w=700&webp=1)
创建存储过程
drop PROCEDURE if exists procedure_split;
CREATE PROCEDURE `procedure_split`(
inputstring varchar(1000),
delim char(1)
)
begin
declare strlen int DEFAULT length(inputstring);
declare last_index int DEFAULT 0;
declare cur_index int DEFAULT 1;
declare cur_char VARCHAR(200);
declare len int;
drop temporary table if exists splittable;
create TEMPORARY table splittable(
value VARCHAR(20)
) ;
WHILE(cur_index<=strlen) DO
begin
if substring(inputstring from cur_index for 1)=delim or cur_index=strlen then
set len=cur_index-last_index-1;
if cur_index=strlen then
set len=len+1;
end if;
insert into splittable(`value`)values(substring(inputstring from (last_index+1) for len));
set last_index=cur_index;
end if;
set cur_index=cur_index+1;
END;
end while;
end ;
处理字符串:
call PROCEDURE_split('1,2,3',',');
读取结果:
select * from splittable;
结果:
![[mysql数据库] 查询结果为数组,怎样切割成字符串,再进行查询 [mysql数据库] 查询结果为数组,怎样切割成字符串,再进行查询](https://image.shishitao.com:8440/aHR0cHM6Ly93d3cuaXRkYWFuLmNvbS9nby9hSFIwY0hNNkx5OXBiV2N0WW1KekxtTnpaRzR1Ym1WMEwzVndiRzloWkM4eU1ERTNNREl2TWpndk1UUTRPREkyTnpJNU5GOHpPVGs0TlRjdWFuQm4%3D.jpg?w=700&webp=1)