日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

oracle汉字排序

發布時間:2024/1/8 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 oracle汉字排序 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

最近項目過程中碰到對于數據進行排序按照升序排序需求。這需求貌似很簡單,我沒多想直接order by columnName。忽略了漢字排序的問題導致bug的出現。


業務要求,按照excel中排序出來的結果。對于漢字excel默認是按照拼音排序的,那么問題來了,oracle對于漢字究竟是如何排序的?

經查閱資料發現,對于oracle對漢字排序的問題網上說法不一。有的說是根據二進制編碼排序的,有的缺說是根據拼音排序的。

自己試了試,肯定默認不是拼音排序。可能是二進制編碼吧。


說下具體怎么改,也是轉載網上的一些方法。

1、語句級別設置排序方式:
? ? ?
//按照筆劃排序?
? ?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、Session級別的設置,修改ORACLE字段的默認排序方式:
?????
?????????按拼音:alter session set nls_sort = SCHINESE_PINYIN_M;
??????????????按筆畫:alter session set nls_sort = SCHINESE_STROKE_M;
??????????????按偏旁:alter session set nls_sort = NLS_SORT=SCHINESE_RADICAL_M;

3、修改系統參數(數據庫所在操作系統):
???????????????set NLS_SORT=SCHINESE_RADICAL_M ;export NLS_SORT (sh)setenv NLS_SORT SCHINESE_RADICAL_M (csh)??HKLCSOFTWAREORACLEhome0NLS_SORT (win注冊表)


我這里只是用來語句級別的就可以了。


回到系統默認排序的問題就是設置數據庫的NLS_SORT 這個參數

通過查看select * from nls_database_parameters; 數據庫參數

我的默認值為BINARY

Oracle 官方說明

Property

Description

Parameter type

String

Syntax

NLS_SORT = { BINARY |?linguistic_definition?}

Default value

Derived from NLS_LANGUAGE

Modifiable

ALTER SESSION

Range of values

BINARY or any valid linguistic definition name

?

  • If the value is BINARY, then the collating sequence for ORDER BY queries is based on the numeric value of characters (a binary sort that requires less system overhead).
  • If the value is a named linguistic sort, sorting is based on the order of the defined linguistic sort. Most (but not all) languages supported by the NLS_LANGUAGE parameter also support a linguistic sort with the same name.

    Note:

    Setting NLS_SORT to anything other than BINARY causes a sort to use a full table scan, regardless of the path chosen by the optimizer. BINARY is the exception because indexes are built according to a binary order of keys. Thus the optimizer can use an index to satisfy the ORDER BY clause when NLS_SORT is set to BINARY. If NLS_SORT is set to any linguistic sort, the optimizer must include a full table scan and a full sort in the execution plan.

???????? You must use the NLS_SORT operator with comparison operations if you want the linguistic sort behavior.



英文水平有限,大概BINARY?這個意思是二進制編碼排序的設定。

總結

以上是生活随笔為你收集整理的oracle汉字排序的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。