Turn: sql statement - sort by the first letter of Chinese pinyin

Reprint link: http://blog.csdn.net/t_332741160/article/details/43308551#

 

1. Oracle :      
Added the sorting function according to pinyin, radicals and strokes in oracle9i. Set NLS_SORT value 
SCHINESE_RADICAL_M Sort by radical (first order) and stroke (second order) 
SCHINESE_STROKE_M Sort by stroke (first order) and radical (second order) 
SCHINESE_PINYIN_M Sort by pinyin, the default sorting method of the system is pinyin sort 
     
An example is as follows: 
the table name is dept, and the name field is Chinese. The following implements the sorting according to the strokes, radicals and pinyin of the unit name.

-- Sort by stroke  
select * from dept order by nlssort(name,'NLS_SORT=SCHINESE_STROKE_M');  
--sort by radical  
select * from dept order by nlssort(name,'NLS_SORT=SCHINESE_RADICAL_M');  
--Sort by pinyin, this is the default sorting method of the system  
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

Reposter's Note:

The first and the second are the content in the reprint. At present, only the second one has been tried. Because there is no oracle environment, I have not tried it. The third one is often used by individuals and has not had any problems.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326270031&siteId=291194637