【oracle】NLS_SORT和NLS_COMP的设置

NLS_SORT和NLS_COMP是Oracle两个初始化参数。顾名思义,NLS_SORT和NLS_COMP是设置排序和比较的方式。通过设置这两个参数可以实现自定义的排序和比较的方式。设置这两个参数的值可以在数据库创建的时候指定,也可以通过Alter Session语句来修改。如果是在创建数据库的时候设定,那么是不能再修改的,并在所有的Session中起作用。但是我们也通过Alter Session命令临时改变这两个参数的值,在会话中临时使用一种特定的排序和比较的方式。要改变所有的会话的排序和比较的方式,我们也可以通过修改注册表的方式来达到目的,如果系统采用的多层体系架构,并且所有的逻辑层代码都部署在相同的应用程序服务器(如IIS)上的。

查看会话中这两个参数值,我们可以使用如下的查询语句:

select * from NLS_SESSION_PARAMETERS; 

官方的文档说明:
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",那么就会引起全表扫描,是不会使用索引的

你可能感兴趣的:(【oracle】NLS_SORT和NLS_COMP的设置)