关于mysql数据库将查询到的int型数据转换成string型报错的解决方法
我们在查询数据库时,时常需要将查询到的数据进行类型转换。
我在将int型数据转换成string型数据时,数据库报了一个错误:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use........
使用的数据库查询语句为:
select cast(id as varchar) as ID from........
使用的mysql服务器版本为:
解决方法为将varchar改为char:
select cast(id as char) as ID from........
再次查询,发现没有报错,成功运行,猜想报错的原因可能是服务器版本的问题。