转:sql语句-按照汉字拼音首字母排序

转载链接:http://blog.csdn.net/t_332741160/article/details/43308551#

1、oracle      
在oracle9i中新增了按照拼音、部首、笔画排序功能。设置NLS_SORT值 
SCHINESE_RADICAL_M 按照部首(第一顺序)、笔划(第二顺序)排序 
SCHINESE_STROKE_M 按照笔划(第一顺序)、部首(第二顺序)排序 
SCHINESE_PINYIN_M 按照拼音排序,系统的默认排序方式为拼音排序 
     
举例如下: 
表名为 dept ,其中name字段是中文,下面分别实现按照单位名称的笔划、部首和拼音排序。

--按照笔划排序  
select * from dept order by nlssort(name,'NLS_SORT=SCHINESE_STROKE_M');  
--按照部首排序  
select * from dept order by nlssort(name,'NLS_SORT=SCHINESE_RADICAL_M');  
--按照拼音排序,此为系统的默认排序方式  
select * from dept order by nlssort(name,'NLS_SORT=SCHINESE_PINYIN_M');  

2、SQL Server

select * from tableName order by name collate Chinese_PRC_CS_AS_KS_WS

 3、MySQL

select * from tableName order by convert(name using gbk) asc,id asc 

转者注:

第一种和第二种是转载中的内容,目前只试过第二种,因为没有oracle环境所以没试。第三个是个人经常用的,没出现过问题。

猜你喜欢

转载自1017401036.iteye.com/blog/2374862
今日推荐