您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

MySQL-procedure小试牛刀_MySQL

2025/10/20 12:07:52发布12次查看
根据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_cnt0 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;
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product