mysql concat乱码

mysql 把查询结果用concat连接时,有时会出现乱码,原因是你的字段类型造成的,只需要使用convert(字段,char)进行转一下就可以了。

create table test(
    id int,
    name varchar(20),
    birth date
);

 当使用 select concat(id,name,birth) as str from test时,会发现查询出的结果是乱码,就算查询出的结果不是乱码,使用其它语言调用时,也会出现乱码。对于这种情况,使用convert函数就可以很好的解决。

select concat(convert(id,char),convert(name,char),convert(birth,char)) as str from test

这样就可以了

猜你喜欢

转载自llyilo.iteye.com/blog/2267930
今日推荐