0
我在MySQL表格中有一列是格式爲csv的中文文本。我有興趣提取包含字符'*'的這些csv列表的成員。什麼是最簡單的方法來做到這一點?如何提取包含特定字符的MySQL表中csv列的成員?
我在MySQL表格中有一列是格式爲csv的中文文本。我有興趣提取包含字符'*'的這些csv列表的成員。什麼是最簡單的方法來做到這一點?如何提取包含特定字符的MySQL表中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)
這個簡單的例子工作,但我得到的錯誤,當我嘗試在我感興趣的數據庫中使用它。例如,ERROR 1436(HY000):線程堆棧溢出:131072 131072一字節堆棧的使用5512個字節,需要的字節。使用'mysqld -O thread_stack =#'指定一個更大的堆棧。 – jonderry 2011-06-06 23:49:50
要澄清,你有一個字段的值是:「一」,「二」,「三*」,你想只是檢索「三*」?或者你想檢索整個記錄? – dmcnelis 2011-06-06 17:21:10
我只想檢索「三*」。本專欄和許多行都有大量的文字。我正試圖專注於本專欄中這些csv列表的這些成員。 – jonderry 2011-06-06 17:23:25