mysql 嵌套 cursor 出錯

dongdongsdo0310 2012-03-26 07:18:40
BEGIN
declare no_more_rows BOOLEAN default false;
declare no_more_rows_new BOOLEAN default false;
declare p_task int;
declare p_predecessor int;
declare p_type varchar(155);
declare p_lag int;
declare p_created varchar(50);
declare p_modified varchar(50);
declare t_id int;
declare t_pre_task int;
declare count_f int default 0;
declare cur_predecessor cursor for
select task,predecessor,type,lag,created,modified from midtasks_predecessor;
declare continue handler for not found set no_more_rows = true;

open cur_predecessor;
the_loop: LOOP
fetch cur_predecessor into p_task,p_predecessor,p_type,p_lag,p_created,p_modified;
if no_more_rows = true then
CLOSE cur_predecessor;
LEAVE the_loop;
end if;
begin
declare cur_task cursor for
select id , pre_task from midtasks where project = copy_id_pro;
declare continue handler for not found set no_more_rows_new = true;
open cur_task;
the_loop_new : LOOP
fetch cur_task into t_id,t_pre_task;
if no_more_rows_new = true then
CLOSE cur_task;
LEAVE the_loop_new;
begin
if p_task = t_pre_task then
insert into midtasks_predecessor(task,predecessor,type,lag,created) values (t_id,(select id from midtasks where pre_task = p_predecessor limit 0,1),p_type,p_lag,sysdate());
end if;
end;
end LOOP the_loop_new;
end;
end LOOP the_loop;
END



錯誤報的是最后的語法錯誤,但是真心看不出來了 ,求大神
...全文
75 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
ACMAIN_CHM 2012-03-26
  • 打赏
  • 举报
回复
BEGIN
declare no_more_rows BOOLEAN default false;
declare no_more_rows_new BOOLEAN default false;
declare p_task int;
declare p_predecessor int;
declare p_type varchar(155);
declare p_lag int;
declare p_created varchar(50);
declare p_modified varchar(50);
declare t_id int;
declare t_pre_task int;
declare count_f int default 0;
declare cur_predecessor cursor for
select task,predecessor,type,lag,created,modified from midtasks_predecessor;
declare cur_task cursor for
select id , pre_task from midtasks where project = copy_id_pro;

declare continue handler for not found set no_more_rows_new = true;

open cur_predecessor;
the_loop: LOOP
fetch cur_predecessor into p_task,p_predecessor,p_type,p_lag,p_created,p_modified;
if no_more_rows = true then
CLOSE cur_predecessor;
LEAVE the_loop;
end if;
begin

open cur_task;
the_loop_new : LOOP
fetch cur_task into t_id,t_pre_ta
ACMAIN_CHM 2012-03-26
  • 打赏
  • 举报
回复
declare 必须放在一开始。
dongdongsdo0310 2012-03-26
  • 打赏
  • 举报
回复
還有不對 , 請問怎么只有外層在循環 內層的怎么不循環啊?
dongdongsdo0310 2012-03-26
  • 打赏
  • 举报
回复
我找出來了 不麻煩大家來了

56,687

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧