database - MySQL cursor fetch NULL -


why both variables output null? select part of cursor working properly.

create procedure p2()   begin     # account table     declare accountid int;     declare accountname varchar(1000);      # 1. cursor finished/done variable comes first     declare done int default 0;     # 2. curser declaration , select     declare c_account_id_name cursor select                                            accountid,                                            accountname                                          temp.test;     # 3. continue handler defined last     declare continue handler sqlstate '02000' set done = true;      open c_account_id_name;     set accountid = 0;     set accountname = '';      read_loop: loop       fetch c_account_id_name       accountid, accountname;       if done               leave read_loop;       end if;       select accountname;     end loop;   end; 

enter image description here

variable , select attribute in cursor can't same...it's mysql bug. work

drop procedure if exists p2; delimiter $$ create procedure p2()   begin     # account table     declare v_accountidsome int;  #pay attention     declare v_accountnameelst varchar(1000); #pay attention      # 1. cursor finished/done variable comes first     declare v_done int default false;     # 2. cursor declaration , select     declare c_account_id_name cursor select                                            accountid, #pay attention                                            accountname #pay attention                                          temp.test;     # 3. continue handler defined last     declare continue handler sqlstate '02000' set v_done = true;      open c_account_id_name;      read_loop: loop       fetch c_account_id_name       v_accountidsome, v_accountnameelst;       if v_done               leave read_loop;       end if;       select v_accountidsome;       select v_accountnameelst;     end loop;     close c_account_id_name;   end $$ delimiter ;  call p2(); 

find more here


Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -