MYSQL Stored Procedure Issues -


i writing mysql stored procedure first time, , running issue - think handler code. basically, want code update rows in pps_users table, reason hitting 'finished condition' handler after 2 rows fetched.

i tried same thing repeat syntax , got same result. if run cursor query correctly 10,000 records expect, when run whole thing is, hit finished code after 1 or 2 records.

delimiter $$  create definer=`root`@`localhost` procedure `changenflfavteams`() begin     declare favnflteam varchar(100) default "";         declare favncaateam varchar(100) default "";         declare v_finished integer default 0;     declare user_id bigint(20);     declare fullnameofteam varchar(100) default "";      declare update_favs cursor select id, favorite_nfl_team pps_users favorite_nfl_team not null;     declare continue handler not found set v_finished = 1;         open update_favs;       updaterecord: loop     fetch update_favs user_id, favnflteam;          select user_id, favnflteam "test";          if v_finished = 1                     select "finished" "finished";             leave updaterecord;         end if;          select full_name fullnameofteam                                 teams t                                  inner join display_names dt on dt.entity_id = t.id                                  , dt.entity_type = 'teams'                                  , dt.first_name = favnflteam                                 , team_key 'l.nfl.com%' limit 1;      select user_id, fullnameofteam "beforeupdate";              if fullnameofteam != ''                            -- here whatever_transformation_may_be_desired             -- find full name record chose                 update pps_users p                 set favorite_nfl_team = fullnameofteam                user_id = p.id;             else                 select 'a' 'a'; -- no op             end if;       end loop updaterecord;    close update_favs;  end 

this because if select full_name fullnameofteam... query returns no rows, set v_finished 1. that, apparently, happens on, , forces exit main loop.

the key realize continue handler not found not apply cursor alone.

you should either put secondary query own begin..end block own continue handler, or (easier) set v_finished = 0 after select full_name fullnameofteam... statement.


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -