您的位置:首页 > MySQL MySQL
站内搜索

MySQL

根据spam_keyword表中的kid对word列逐行逐字分割到t表中,并且统计每个字的数量。

用了两层循环,外循环游标读行,内循环stroo++读字。

drop procedure if exists proc134f;CREATE PROCEDURE proc134f()BEGINdeclare kidoo int;declare tid int;declare stroo int;declare str varchar(255);declare strlength int;declare istr varchar(3);declare istr_cnt int;declare done int;-- 游标用declare cur_kid CURSOR for select kid from spam_keyword;-- 游标用declare continue handler for not found set done=1;-- 游标用,据说是直达引擎的通道set tid=0;delete from t;open cur_kid;-- 开启游标loop1:loop-- 开启1层外循环fetch cur_kid into kidoo;    -- 从定义的范围中读取下一行并赋予if done=1 then leave loop1;end if;-- 判断是否 found 下一行,否则跳出select word into str from spam_keyword where kid=kidoo;set str=replace(str,' ','');set strlength=char_length(str);set stroo=0;loop2:loop-- 2层内循环set stroo=stroo+1;set istr=substr(str,stroo,1);select count(*) into istr_cnt from t where t=istr;-- 计数if istr_cnt<>0 then update t set cnt=cnt+1 where t=istr;elseset tid=tid+1;insert into t set id=tid,t=istr,cnt=1;end if;if stroo>=strlength then leave loop2;end if;end loop loop2;set done=0;end loop loop1;close cur_kid;-- 关闭游标select * from t order by cnt desc;END;
  • 上一篇:MySQL中的?加关键字查询命令用法_MySQL
  • 下一篇:Innodb三大特性之double write_MySQL