存储过程的内容如下:
begin
declare tagid int;
declare tag_d_id int;
declare fetch_tag_ok boolean default false;
declare tag_d_cur cursor for select temp_tag_id from temp_tags where is_saved=1;//三条结果
declare continue handler for NOT FOUND set fetch_tag_ok = true;
set fetch_tag_ok=false;
open tag_d_cur;
tag_access_loop:loop
if fetch_tag_ok then
leave tag_access_loop;
else
fetch tag_d_cur into tagid;
select id into tag_d_id from tag_dimension where tag_id=tagid;
insert into tag_access_facts(date_id,time_id,user_id,tag_id)values(tagid,1,1,tag_d_id);#测试。。
end if;
end loop tag_access_loop;
close tag_d_cur;
set fetch_tag_ok=false;
end
结果应该是在tag_access_facts中存在三条记录,因为游标中只有三条记录,但是在tag_access_facts中却是四条记录,最后一条重复了一次。
这代码是有问题的,正常的流程应该是
FETCH cursor INTO xxxx;
IF fetch_tag_ok THEN
OK,问题解决了,多谢老大。