cursor - In MySQL, i am not being able to execute commands after a loop -
i using cursor , loop execute stored procedure on each item of table. need done once day. procedure works , executes daily procedure on each row of table. part works fine. but, when try adding logging @ end (updating of table rollupcontrol time execution took) command doesn't executed @ all... added 2 debugging selects, 1 inside loop , other outside. 1 inside gets executed 1 outside doesn't...
drop procedure if exists `runx`; delimiter $$ create procedure `runx`() runx:begin -- roda rup366 uma vez para cada dispositivo declare t0 datetime(2) default now(2); declare t0i float default 0; declare debug int default 1; declare viddisp varchar(6); declare done boolean default false; declare _id bigint unsigned; declare cur cursor (select id tablem m join tabler r on m.id = r.id time_to_sec(timediff(lastupdatedtime,lastqueryedtime))/(60*60*24) > 1); declare continue handler not found set done := true; open cur; runxloop: loop fetch cur _id; if done leave runx; end if; set viddisp = (select iddisp tablem id = _id); if debug=1 select viddisp; end if; call runonceadayproc(viddisp); end loop runxloop; if debug=1 select t0i; end if; set t0i = (select timestampdiff(microsecond,t0,now(2))/1000000); update rollupcontrol set dh_op = now(), et = t0i id = 366; close cur; end$$ delimiter ;
i thinking
leave runx;
should
leave runxloop;
Comments
Post a Comment