PostgreSQL下,對漢字按拼音排序


參考學習此文:

http://blog.163.com/digoal@126/blog/static/163877040201173003547236/

建庫

postgres=# \l
                                  List of databases
   Name    |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges   
-----------+----------+----------+-------------+-------------+-----------------------
 db_utf8   | gao      | UTF8     | zh_CN.UTF-8 | zh_CN.UTF-8 | 
 postgres  | postgres | UTF8     | zh_CN.UTF-8 | zh_CN.UTF-8 | 
 template0 | postgres | UTF8     | zh_CN.UTF-8 | zh_CN.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
 template1 | postgres | UTF8     | zh_CN.UTF-8 | zh_CN.UTF-8 | =c/postgres          +
           |          |          |             |             | postgres=CTc/postgres
(4 rows)

postgres=# 

建表

postgres=# \d
               List of relations
 Schema |       Name        | Type  |  Owner   
--------+-------------------+-------+----------
 public | gao_chinese_order | table | postgres
 public | tbl_chinese_order | table | postgres
(2 rows)

postgres=# 
 insert into tbl_chinese_order values ('劉少奇');

insert into tbl_chinese_order values ('劉德華');

insert into tbl_chinese_order values ('張學友');

普通排序

postgres=# select * from tbl_chinese_order order by info;
  info  
--------
 劉少奇
 劉德華
 張學友
(3 rows)
postgres=# select * from tbl_chinese_order order by convert_to(info,'SQL_ASCII');
  info  
--------
 劉少奇
 劉德華
 張學友
(3 rows)

postgres=# 

按拼音排序:

postgres=# select * from tbl_chinese_order order by convert_to(info,'GBK');
  info  
--------
 劉德華
 劉少奇
 張學友
(3 rows)

postgres=#
postgres=# select * from tbl_chinese_order order by convert_to(info,'GB18030');
  info  
--------
 劉德華
 劉少奇
 張學友
(3 rows)

postgres=# 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM