Oracle 参数 NLS_SORT 官方解释,作用,如何配置最优化建议

本站中文解释

NLS_SORT参数是定义排序法的参数,可以在alter session语句中设定,其值可以为可识别的语言类型,比如CHINESE,FRENCH,GERMAN等等。

NLS_SORT指定排序类型,将影响字段类型的排序、空值处理和比较多字段项。如果NLS_SORT参数未被正确设置的话,则按照Oracle的默认系统参数设置排序方法。

正确设置NLS_SORT参数的步骤如下:

1. 首先,我们可以使用NLS_SORT参数來指定Oracle识别的语言,例如:ALTER SESSION SET NLS_SORT=CHINESE;

2. 然后,可以使用 NLS_COMP参数来设置排序比较算法模式,设置值有:BINARY、LINGUISTIC和ANSI,分别表示二进制比较、语言比较和通用ANSI SQL模式。例如:ALTER SESSION SET NLS_COMP=LINGUISTIC;

3. 最后,使用NLS_SORT参数来指定排序规则,可以设置的值有XCHINESE_P_CS(优先排序发音字符)、XCHINESE_P_CI(优先排序书写字符)和XCHINESE_CI(书写字符排序)。例如:ALTER SESSION SET NLS_SORT=XCHINESE_P_CS;

上面3步可以满足中文排序需求,最后确认设置参数是否正确,可以使用col NLS_来检查:SELECT * FROM V$NLS_PARAMETERS;

官方英文解释

NLS_SORT specifies the collating sequence for character value comparison in various SQL operators and clauses.

Property Description

Parameter type

String

Syntax

NLS_SORT = { BINARY | linguistic_definition }

Default value

Derived from NLS_LANGUAGE

Modifiable

ALTER SESSION

Modifiable in a PDB

Yes

Range of values

BINARY or any valid linguistic definition name

Basic

No

For example, NLS_SORT specifies the collating sequence for character value comparison in these SQL operators and clauses: 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 telephone directories in those languages.

The exact operators and query clauses that obey the NLS_SORT parameter depend on the value of the NLS_COMP parameter. If an operator or clause does not obey the NLS_SORT value, as determined by NLS_COMP, the collation used is BINARY.

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.

Note:

The value of the initialization parameter NLS_SORT is used to initialize the session value of this parameter, which is the actual value referenced by the SQL query processing. This initial value is overriden by a client-side value if the client uses the Oracle JDBC driver or if the client is OCI-based and the NLS_LANG client setting (environment variable) is defined. The initialization parameter value is, therefore, usually ignored.

See Also:

  • Oracle Database
    Globalization Support Guide
    for more information about this parameter and a current listing of values you can specify


数据运维技术 » Oracle 参数 NLS_SORT 官方解释,作用,如何配置最优化建议