Mysql存储过程获取错误

时间:2015-06-10 19:55:07

标签: mysql loops stored-procedures

我做错了什么?

CREATE DEFINER=`root`@`localhost` PROCEDURE `getAllPoints`()
BEGIN
declare done1, done2, done3, done4, pointAlive BOOLEAN DEFAULT FALSE;
*lots of declaring*
...
*lots of declaring*


declare cur1 cursor for select id, Owner_idOwner, longitude, lat,x,y from Point;
declare continue handler for not found set done1= TRUE;

DROP TEMPORARY TABLE IF EXISTS TEMP;
CREATE temporary TABLE IF NOT EXISTS TEMP (
*lots of stuff*

)ENGINE=MEMORY;
open cur1;

mainLoop: loop
fetch cur1 into pointid, ownerid, pointlong, pointlat, pointx,pointy;

if done1 then 
set done1 = FALSE;
close cur1;
leave mainLoop;
end if;
insert into TEMP (тут работает);

BLOCK2:BEGIN
** Black is working right with cursor #1***

END BLOCK2 ;
BLOCK3:BEGIN
** Black is working right with cursor #2***
END BLOCK3;

那是不起作用的:

pointid声明int从cur1光标获取值“18045”

call isAlive(pointid,@Alive,@timeTill);
update TEMP set Open = @Alive, TimeTill= @timeTill where Point_id = pointid;

end loop mainLoop;
select * from TEMP; 

调用isAlive循环似乎被中断并且选择查询在Open和TimeTill列中仅返回正确值的1行而不是在未调用isAlive时具有正确值的~1200rows

END

这是isAlive存储过程:

CREATE DEFINER=`root`@`localhost` PROCEDURE `isAlive`(IN iPoint_id int, INOUT Alive int, INOUT timeTill time)
BEGIN
declare pointAlive int;
select count(id) into pointAlive from Schedule where 
day = dayofweek(curdate())-1 
and Point_id = iPoint_id 
and Start < curtime() 
and Stop > curtime();

if poinTalive then
select pointAlive,timediff(Stop,curtime()) INTO Alive, timeTill
from Points.Schedule 
where day = dayofweek(curdate()) -1 
and Point_id = iPoint_id;
else
select pointAlive,timediff(str_to_date(concat(curdate(),' ',@starttime), "%Y-%m-%d %T"),now()) INTO Alive, timeTill
from Points.Schedule 
where day = dayofweek(curdate()) -1
and Point_id = iPoint_id;
end if;

END

你能告诉我我做错了什么吗?如何为每个isAlive致电pointid?谢谢

0 个答案:

没有答案