zoukankan      html  css  js  c++  java
  • PostgreSQL对汉字按拼音排序

    转自:https://www.cnblogs.com/gaojian/p/3188609.html

    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=#
    脚踏实地,仰望星空。
  • 相关阅读:
    Java之List使用方法
    Java之数组遍历
    收集关于前端的一些网站、博客资源、框架、源码等 、 会持续更新哦!!!!!
    css常用代码含义
    css两列等高布局
    HTML之DocType的几种类型
    CSS实现圆角的方法
    IE6图片元素img下出现多余空白问题
    web标准常见问题整理
    好的 Web 前端年薪会有多少?
  • 原文地址:https://www.cnblogs.com/sijizhen/p/10754274.html
Copyright © 2011-2022 走看看