介绍下这个过程希望实现的功能,表brandlist里放的是品牌名brandkey,表temp_no里放的是关键词uni_kw,想在表temp_no的每个uni_kw中循环查找品牌名,如果包含某个品牌名,即更新变量tempbrand,最后将这个变量update到表temp_no中此uni_kw对应的brand字段。brandlist表内的记录为100+,temp_no本来的数据量为500W,此过程运行了一个晚上还没有执行完,后来我将temp_no的数据量调整为3W,过程20分钟执行完了,但是Affected rows: 0 ,brand字段没有改变。过程的数据访问设置为modifies sql data,权限应该没有问题。不知道是程序逻辑有问题还是语句有问题,我是mySQL的新手,特来请教各位。begin
declare this_id int;
declare this_kw varchar(100);
declare done int default 0;
declare c1 cursor for select uni_id,uni_kw from temp_no;
declare continue handler for not found set done=1;open c1;
c1:Loop
if done=1 then
leave c1;
else
fetch c1 into this_id,this_kw;
begin
declare this_brand varchar(20);
declare tempbrand varchar(50);
declare done2 int default 0;
declare c2 cursor for select brandkey from brandlist;
declare continue handler for not found set done2=1;
open c2;
c2:loop
if done2=1 then
leave c2;
else
fetch c2 into this_brand;
if instr(this_kw,this_brand)>0 then
set tempbrand=concat(tempbrand,';',this_brand);
end if;
end if;
end loop;
update temp_no set brand=tempbrand where uni_id=this_id;
end;
end if;
end loop;
end
declare this_id int;
declare this_kw varchar(100);
declare done int default 0;
declare c1 cursor for select uni_id,uni_kw from temp_no;
declare continue handler for not found set done=1;open c1;
c1:Loop
if done=1 then
leave c1;
else
fetch c1 into this_id,this_kw;
begin
declare this_brand varchar(20);
declare tempbrand varchar(50);
declare done2 int default 0;
declare c2 cursor for select brandkey from brandlist;
declare continue handler for not found set done2=1;
open c2;
c2:loop
if done2=1 then
leave c2;
else
fetch c2 into this_brand;
if instr(this_kw,this_brand)>0 then
set tempbrand=concat(tempbrand,';',this_brand);
end if;
end if;
end loop;
update temp_no set brand=tempbrand where uni_id=this_id;
end;
end if;
end loop;
end
解决方案 »
- mysql 有没有批量 修改 表注释和字段注释 ??
- mysql表中字段的设定问题
- 用mysqldump备份数据库时,会不会Lock表?
- 有什么可以存放多个ID数据?
- 我的mysql装在自各儿的机器上,以前能直接在c:\mysql\bin 后打上mysql后就可以登陆。后来建了个用户用grant 给予授权之后,就不能用mysql
- 再谈关于mysql中文模糊查找问题!
- 转意字符'\0'与NULL有何区别?THANKS
- 设置sql_mode无效果
- 在2000nt里怎么使用MySQL SERVER?还有怎么安装?
- 仿发表说说的MYSQL表设计,索引上增加一个时间字段是否值得
- 请教基于mysql数据库的数据仓库
- 卸载MySQL时,connector .net卸载不了,求解?
begin
declare this_brand varchar(20);
declare tempbrand varchar(50);楼主用的是什么版本?
有3个问题:
1.concat字符连接函数,参数如果有null,则结果为null。而我的变量默认值为null,所以结果都为null没变。
2.update前没有对变量进行判断,导致更新操作频繁,运行效率低
3.游标没有关闭。