MySQL-procedure小试牛刀_MySQL
根据spam_keyword表中的kid对word列逐行逐字分割到t表中,并且统计每个字的数量。
用了两层循环,外循环游标读行,内循环stroo++读字。
drop procedure if exists proc134f; CREATE PROCEDURE proc134f() BEGIN declare 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;else set 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;

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

This article explores optimizing MySQL memory usage in Docker. It discusses monitoring techniques (Docker stats, Performance Schema, external tools) and configuration strategies. These include Docker memory limits, swapping, and cgroups, alongside

The article discusses using MySQL's ALTER TABLE statement to modify tables, including adding/dropping columns, renaming tables/columns, and changing column data types.

This article addresses MySQL's "unable to open shared library" error. The issue stems from MySQL's inability to locate necessary shared libraries (.so/.dll files). Solutions involve verifying library installation via the system's package m

This article compares installing MySQL on Linux directly versus using Podman containers, with/without phpMyAdmin. It details installation steps for each method, emphasizing Podman's advantages in isolation, portability, and reproducibility, but also

This article provides a comprehensive overview of SQLite, a self-contained, serverless relational database. It details SQLite's advantages (simplicity, portability, ease of use) and disadvantages (concurrency limitations, scalability challenges). C

This guide demonstrates installing and managing multiple MySQL versions on macOS using Homebrew. It emphasizes using Homebrew to isolate installations, preventing conflicts. The article details installation, starting/stopping services, and best pra

Article discusses configuring SSL/TLS encryption for MySQL, including certificate generation and verification. Main issue is using self-signed certificates' security implications.[Character count: 159]

Article discusses popular MySQL GUI tools like MySQL Workbench and phpMyAdmin, comparing their features and suitability for beginners and advanced users.[159 characters]
