描述:当创建数据库时某个字段使用【varchar】或者【char】类型的数据(例如:“1”,“2”,“3”…),但是后续需求出现变化,需要对这个字段中的数据有个大小的排序,那么问题来了,字符串形式的数据如何进行类似【int】类型的大小排序?很简单,如下所示的三种情况均可:

select id,dict_name,type_code from t_dictionary  where type_code='GRADE' ORDER BY `dict_name`*1;  
select id,dict_name,type_code from t_dictionary  where type_code='GRADE' ORDER BY dict_name+0;  
select id,dict_name,type_code from t_dictionary  where type_code='GRADE' ORDER BY CAST(dict_name AS DECIMAL);