mysql - 如何提取 MySQL 表中包含特定字符的 csv 列的成员?

标签 mysql

我的 MySQL 表中有一个列是格式为 csv 的中等文本。我有兴趣提取这些 csv 列表中包含字符“*”的成员。最简单的方法是什么?

最佳答案

我从来没有做过类似的事情。正如你所看到的,我做了一个简单的测试。 我不知道大型记录集的性能。

create table mytest (
id int not null auto_increment primary key,
content varchar(100)
) engine = myisam;

insert into mytest (content)
values 
('one,two*,three*text'),
('four,five'),
('six*,seven*,eight*');



delimiter //
drop procedure if exists split_found //
create procedure split_found()
begin
declare str varchar(200);
declare ssql varchar(200);
declare finito int default 0;
declare cursore cursor for select content from mytest;
declare continue handler for not found set finito = 1;
drop temporary table if exists tmp;
create temporary table tmp (cont varchar(50) );
open cursore;
mio_loop:loop
fetch cursore into str;
if finito = 1 then
leave mio_loop;
end if;
 set @ssql = concat("insert into tmp (cont) values ('", replace(str, ',', "'),('"), "')");
 prepare stmt from @ssql;
 execute stmt;
 deallocate prepare stmt;
end loop;
close cursore;
select * from tmp where cont like '%*%';
end; //
delimiter ;

mysql> call split_found();
+------------+
| cont       |
+------------+
| two*       |
| three*text |
| six*       |
| seven*     |
| eight*     |
+------------+
5 rows in set (0.01 sec)

关于mysql - 如何提取 MySQL 表中包含特定字符的 csv 列的成员?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6255637/

相关文章:

java - Hibernate cfg.xml - 无法建立 jdbc 连接

c# - 无法将类型为 'System.DateTime' 的对象转换为类型 'System.String'。 C#

mysql - 需要将mysql group by query转为oracle

mysql - 如何将一个表中的两个元组连接到另一个表中的一个元组

mysql - 是什么让 PostgreSQL 比 MySQL 更先进?

c# - MySql MySqlDataReader 文档?

mysql 使用 LOAD DATA 更​​新表

mysql - 将sql查询WITH子句查询转换为mysql查询

mysql - 'where clause' 中的未知列。嵌套子查询提高 'ORDER BY'的性能

MySQL 全文搜索总是有 0 个结果?