设为首页 收藏本站
查看: 537|回复: 0

[经验分享] oracle数据库拼音排序及NLS_SORT配置[转]

[复制链接]
YunVN网友  发表于 2016-8-14 06:19:54 |阅读模式
    Oracle9i之前,中文是按照二进制编码进行排序的。在oracle9i中新增了按照拼音、部首、笔画排序功能。
  1、设置NLS_SORT参数值
      SCHINESE_RADICAL_M 按照部首(第一顺序)、笔划(第二顺序)排序
      SCHINESE_STROKE_M 按照笔划(第一顺序)、部首(第二顺序)排序
      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、语句级别设置排序方式:
      按照笔划排序
      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');
  4、修改系统参数(数据库所在操作系统):
      set NLS_SORT=SCHINESE_RADICAL_M ;
  export NLS_SORT (sh)
       setenv NLS_SORT SCHINESE_RADICAL_M (csh)
      HKLC\SOFTWARE\ORACLE\home0\NLS_SORT (win注册表)
  
  
  Oracle 官方说明
  
  NLS_SORT NLS_SORT specifies the collating sequence for ORDER BY queries. NLS_COMP NLS_COMP specifies the collation behavior of the database session.
  
  
  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.
  
  
  Property
  Description
  Parameter type
  String
  Syntax
  NLS_COMP = { BINARY | LINGUISTIC | ANSI }
  Default value
  BINARY
  Modifiable
  ALTER SESSION
  Basic
  No
  
  Values:

  • BINARY
  Normally, comparisons in the WHERE clause and in PL/SQL blocks is binary unless you specify the NLSSORT function.

  • LINGUISTIC
  Comparisons for all SQL operations in the WHERE clause and in PL/SQL blocks should use the linguistic sort specified in the NLS_SORT parameter. To improve the performance, you can also define a linguistic index on the column for which you want linguistic comparisons.

  • ANSI
  A setting of ANSI is for backwards compatibility; in general, you should set NLS_COMP to LINGUISTIC
  
  注意:当使用了NLS_SORT或NLS_COMP,应该指定函数索引来提高数据库性能。如
  create index [schema.]indexName on tableName(function(propertyName))
  
  注意:虽然能在oracle查询的时候能用得上,但不知道为什么,当映射到hibernate上时却无效,依然按NLS_SORT=binary排序,不过可以使用@org.hibernate.annotation.OrderBy("nlssort(name,'NLS_SORT=SCHINESE_PINYIN_M')")指定排序方法

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-257264-1-1.html 上篇帖子: oracle行转列的通用实现(管道函数) 下篇帖子: 如何改变Oracle 10g Express Edition默认的8080端口
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表