如何使用while在mysql中搜索许多结果

时间:2016-10-13 21:56:45

标签: mysql stored-procedures

我有两个表,每个表包含一列:列A(表格中为正数)是单词列表,列B(表格中)是长段落列表。

column A         
abound  
abounds  
abundance  
abundant  
accessable  
accessible  
acclaim  
.......

column B
 Works great.....   
 I registered for ....
 We started with the
 This is an excellent idea having the

我即将在B列的段落中搜索A列中每个单词的出现。我从我的朋友那里得到了这个代码,她使用的是SQL服务器。

我的问题是我无法运行代码,因为我不是一个经验丰富的MySQL播放器,而且我不知道如何将代码从SQL服务器转换为MySQL,我试图谷歌,但我失败了。如果有人可以指出需要编辑的地方,我将不胜感激。 我的代码是

DELIMITER //
CREATE PROCEDURE counting ()
BEGIN

DECLARE id int ;
DECLARE max int;
DECLARE count int;
DECLARE word varchar(20);
DECLARE string varchar(500);
DECLARE fake_str varchar(100);
set id = 1
select max(count) from ( SELECT count(word) as count from positive
SELECT max = select count(word) from positive
while id <= max
select word = word from positive where id = id
set fake_str = quotename('%'+ @word +'%','''')
set string = declare count int,id int set count = (select count(*) from bodyTL7P where comments like ' + fake_str + ') print count 
               update positive set times = count' + ' where id = '+ cast(id as varchar)

exec (string)
set id = id + 1

END
select * from positive
//
DELIMITER ;

我从她的计算机中添加测试样本以使事情更加清晰。

Test sample from SQL server

0 个答案:

没有答案