oracle拼音排序

來源:互聯網
上載者:User

標籤:ide   har   alpha   uid   針對   sed   log   release 2   present   

今天做一個需求,要求按照人名排序,最開始沒有怎麼注意,就直接排序了,大致如下。

select * from test_pinyin order by name

後來發現需要使用拼音排序,oracle預設的排序是安裝二進位排序的,這一排序方式是按照字元在他所在的編碼錶裡面的數值的大小進行排序的,二進位排序是最快的一種排序方式,這一排序方式對英語字母表的排序是合理的,但是對於一些其他的語言就不那麼合理了。

Using Binary Sorts One way to sort character data is based on the numeric values of the characters defined by the character encoding scheme. This is called a binary sort. Binary sorts are the fastest type of sort. They produce reasonable results for the English alphabet because the ASCII and EBCDIC standards define the letters A to Z in ascending numeric value. When characters used in other languages are present, a binary sort usually does not produce reasonable results. For example, an ascending ORDER BY query returns the character strings ABC, ABZ, BCD, ?BC, when ? has a higher numeric value than B in the character encoding scheme. A binary sort is not usually linguistically meaningful for Asian languages that use ideographic characters

對於漢字使用拼音來排序的情境還是有很多的,因此特將漢字使用拼音的排序方式記錄一下。

  • 方法一:語句層級設定排序方式

    select * from test_pinyin order by NLSSORT(name,‘NLS_SORT = SCHINESE_PINYIN_M‘)
  • 方法二:設定資料庫的排序參數

    -- 修改系統設定alter system set nls_sort=‘SCHINESE_PINYIN_M‘ scope=spfile
  • 方法三:修改session

    -- 修改sessionalter SESSION set NLS_SORT = SCHINESE_PINYIN_M

    推薦使用第一種方法。

怎麼查看系統的預設排序方式呢?我們可以查相應的字典表,萬能的字典。

-- 查字典,找到關於NLS(National Language Support)的表select * from dict where TABLE_NAME like ‘%NLS%‘-- 查session的NLS排序參數select * from NLS_SESSION_PARAMETERS WHERE PARAMETER = upper(‘nls_sort‘)
參考

1.Oracle中針對中文進行排序
2.Oracle? Database Globalization Support Guide 11g Release 2 (11.2)

oracle拼音排序

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.