一秒钟解决mysql使用游标出现取值乱码问题

drop procedure if exists pro_test;
delimiter //
create procedure pro_test()
begin
  declare str varchar(256) character set utf8 ; #指定变量 的字符集 为 utf8 
  declare str_str varchar(256) character set utf8 default ''; 
  declare done int default 0;
  declare c_person cursor for select title from t_score;
  declare continue handler for not found set done = 1;
  open c_person;
  xxx:loop
    fetch c_person into str;
    if done = 1 then
      leave xxx;
    end if;
    set str_str = concat(str_str,concat(str,'/'));
  end loop;
  select  str_str;
  close c_person;
end //
delimiter ;
call  pro_test();

在变量后指定一个字符集( character set utf8 )。这样就可以了。

  

posted @ 2018-09-19 19:30  追梦滴小蜗牛  阅读(481)  评论(0编辑  收藏  举报