Oracle默认是采用binary进行排序,这对于例如中文的排序来说,是不恰当的。使用这两个参数可以指定排序的方法,比如拼音或是,要注意可能会引起性能问题。
解决方法是使用NLSSORT函数来建立一个函数索引。

NLS_COMP = { BINARY | LINGUISTIC | ANSI }
BINARY
Normally, comparisons in the WHERE clause and in PL/SQL blocks is binary unless you specify theNLSSORT function.
LINGUISTIC
Comparisons for all SQL operations in the WHERE clause and in PL/SQL blocks should use the linguistic sort specified in theNLS_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 setNLS_COMP to LINGUISTIC


NLS_SORT = { BINARY | linguistic_definition
}
NLS_SORT specifies the collating sequence for character value comparison in various SQL operators and clauses, for example, ORDER BY, GROUP BY, comparison conditions (=, <>, <=, >=), IN, BETWEEN, LIKE, MIN/MAX, GREATEST/LEAST, and INSTR.

If the value is BINARY, then comparison is based directly on byte values in the binary encoding of the character values being compared. The ordering depends on the character set of the compared values, which is either the database character set (for VARCHAR2, CHAR, LONG, and CLOB) or the national character set (for NVARCHAR2, NCHAR, and NCLOB).

If the value is a named linguistic sort, then comparison is defined by this sort. A linguistic sort uses various rules to achieve ordering expected by speakers of one or more natural languages. This is usually the same ordering that is used in dictionaries and/or telephone directories in those languages.

The BINARY comparison is faster and uses less resources than any linguistic comparison but for text in a natural language, it does not provide ordering expected by users.
The value of NLS_SORT affects execution plans of queries. Because a standard index cannot be used as a source of values sorted in a linguistic order, an explicit sort operation must usually be performed instead of an index range scan. A functional index on the NLSSORT function may be defined to provide values sorted in a linguistic order and reintroduce the index range scan to the execution plan.

下面做个测试:
首先来看看可用的中文排序方法:
select value from v$nls_valid_values where parameter='SORT' and value like '%SCHINESE%';
返回可用的中文排序方法
SCHINESE_PINYIN_M    -- 按照拼音排序
SCHINESE_STROKE_M -- 按照笔划(第一顺序)、部首(第二顺序)排序
SCHINESE_RADICAL_M -- 按照部首(第一顺序)、笔划(第二顺序)排序

========================

NLS_SORT specifies the collating sequence for ORDER BY queries.

  • 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.

根据上文中标红部分的注视,如果NLS_SORT不是设置为"Binary",那么就会引起全表扫描,是不会使用索引的.

NLS_COMP specifies the collation behavior of the database session.

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

《FROM:http://www.linuxidc.com/Linux/2012-09/70931.htm http://www.cnblogs.com/yanrongpi/archive/2008/04/11/1149144.html

NLS_COMP和NLS_SORT参数的更多相关文章

  1. Oracle 常用函数大全

    Oracle 11g 常用函数(Functions)详解 目录 ABS. 3 ACOS. 3 ADD_MONTHS. 4 ASCII 4 ASCIISTR. 5 ASIN.. 5 ATAN.. 5 A ...

  2. [转]Show parameter & Table Not exists

    本文转自:http://www.cnblogs.com/fangwenyu/archive/2011/01/06/1926774.html 问题描述 在尝试通过show parameter来查看一个参 ...

  3. Oracle 实现查询不区分大小写(设置数据库)

    转http://blog.csdn.net/shl7765856/article/details/7622756 查询数据的时候. SQL Server 默认 不区分大小写. 如果要区分,就要额外的设 ...

  4. Oracle SQL函数-NLSSORT

    Syntax 用途: NLSSORT返回字符值char的排序规则键和显式或隐式指定的排序规则.排序规则键是一个用于根据指定的排序规则对char进行排序的字节字符串.排序规则键的属性是:按二进制比较由给 ...

  5. Oracle 数据类型比较规则

    数值 较大的值被认为大于较小的值.所有负数都小于零,所有正数都小于零.因此,-1小于100:-100小于-1. 浮点值NaN(not a number))大于任何其他数值,且等于自身. 日期时间值 较 ...

  6. 1Z0-053 争议题目解析470

    1Z0-053 争议题目解析470 考试科目:1Z0-053 题库版本:V13.02 题库中原题为: 470.Which NLS parameter can be used to change the ...

  7. OCP读书笔记(25) - 题库(ExamE)

    401.Which of the following are correct about block media recovery? (Choose all that apply.)A. Physic ...

  8. oracle已知会导致错误结果的bug列表(Bug Issues Known to cause Wrong Results)

    LAST UPDATE:     1 Dec 15, 2016 APPLIES TO:     1 2 3 4 Oracle Database - Enterprise Edition - Versi ...

  9. regexp_replace

    pandas和SQL数据分析实战 https://study.163.com/course/courseMain.htm?courseId=1006383008&share=2&sha ...

随机推荐

  1. PHP MySQL Where 子句 之Where

    WHERE 子句 如需选取匹配指定条件的数据,请向 SELECT 语句添加 WHERE 子句. 语法 SELECT column FROM table WHERE column operator va ...

  2. JS~JS里的数据类型

    JS里的数据类型,它虽然是个弱类型的语言,但它也有自己的规定的,它不会向其它语言那么,使用int来声明一个整形变量,而是使用 var,如果你是一个C#的开发者,你就会知道,原来C#现在也在和JS学,开 ...

  3. Oracle SQL函数之转换函数

    chartorowid(c1) [功能]转换varchar2类型为rowid值 [参数]c1,字符串,长度为18的字符串,字符串必须符合rowid格式 [返回]返回rowid值 [示例] SQL> ...

  4. windows下sqlplus / as sysdba报ora-12560的解决方法

    环境:win7_64位.数据库版本ORACLE11G_R2 在CMD窗口,使用下面三个命令可正常连接数据库:C:\Users\Administrator> sqplus /nolog C:\Us ...

  5. [KMP求最小循环节][HDU1358][Period]

    题意 求所有循环次数大于1的前缀 的最大循环次数和前缀位置 解法 直接用KMP求最小循环节 当满足i%(i-next[i])&&next[i]!=0 前缀循环次数大于1 最小循环节是i ...

  6. onvif规范的实现:成功实现ONVIF协议RTSP-Video-Stream与OnvifDeviceManager的视频对接

    有了前几篇的基础,现在可以正式开始onvif的实现工作,其中一项非常重要的部分就是视频流的对接,即能够在符合onvif标准的监控客户端软件里接收到设备端NVT发来的RTSP视频流.这里,我所用的客户端 ...

  7. .NET 下成熟开源的BPM产品四款推荐

    .net下的BPM产品相比JAVA的确实不多,这里主要提4款. 1.博客园.github.codeplex上的开源的流程组件AppInOne BPM,目前已有不少的企业开始使用. 优点:产品框架较全面 ...

  8. c# 面相对象2-之封装性

    一.封装特性: 这是一种隐藏的特性.可以用一个公式来展示类的封装特性: 封装的类=数据  +  对此数据进行的操作(即算法) 通俗的说,封装就是:包起外界不必要知道的东西,只向外界展露可供展示的东西. ...

  9. Android常用组件Broadcast介绍

    一.Broadcast简介 Broadcast是Android的四大组件之一.可分为: 1.普通广播 发送一个广播,所有监听该广播的广播接收者都可以监听到改广播. 2.异步广播 当处理完之后的Inte ...

  10. MVC 全局异常过滤器HandleErrorAttribute

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...