`

NLS_SORT设置

阅读更多

Oracle数据库中文拼音排序问题,NLS_SORT设置

Oracle9i之前,中文是按照二进制编码进行排序的。在oracle9i中新增了按照拼音、部首、笔画排序功能。

1、设置NLS_SORT参数值

SCHINESE_RADICAL_M 按照部首(第一顺序)、笔划(第二顺序)排序

SCHINESE_STROKE_M 按照笔划(第一顺序)、部首(第二顺序)排序

SCHINESE_PINYIN_M 按照拼音排序

BINARY_CI 忽略大小写的排序

2、Session级别的设置,修改ORACLE字段的默认排序方式:

按拼音:alter session set nls_sort = SCHINESE_PINYIN_M;

按笔画:alter session set nls_sort = SCHINESE_STROKE_M;

按偏旁:alter session set nls_sort = SCHINESE_RADICAL_M;

忽略大小写:alter session set nls_sort = BINARY_CI

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');

忽略大小写 

select * from dept order by nlssort(name,'NLS_SORT=BINARY_CI');

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注册表)

5、设置查询时忽略大小写方法:

alter session set nls_sort='BINARY_CI';

alter session set nls_comp='LINGUISTIC';

 

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所有的值请在v$nls_valid_values视图中找

分享到:
评论

相关推荐

    中文排序方式:拼音,笔画,边傍

    1.根据拼音排序 2.根据笔画排序 3.根据偏旁排序 <br>系统的默认排序方式为拼音排序,可以通过修改nls_sort参数修改 alter session set nls_sort = SCHINESE_STROKE_M;

    oracle详解

    将sort_area_size设置为一个较大的值,比如100M 2.避免日志切换等待 增加重做日志组的数量,增大日志文件大小. 3.优化日志缓冲区 比如将log_buffer容量扩大10倍(最大不要超过5M) 4.使用阵列插入与提交 commit = y 注意...

    oracle指定排序的方法详解

     1、设置NLS_SORT参数值 SCHINESE_RADICAL_M 按照部首(第一顺序)、笔划(第二顺序)排序 SCHINESE_STROKE_M 按照笔划(第一顺序)、部首(第二顺序)排序 SCHINESE_PINYIN_M 按照拼音排序  2、Session级别的...

    Oracle 中文字段进行排序的sql语句

    1)按笔画排序 select * from Table order by nlssort(columnName,’NLS_SORT=SCHINESE_STROKE_M’) 2)按部首排序 select * from Table order by nlssort(columnName,’NLS_SORT=SCHINESE_RADICAL_M’) 3)按拼音...

    Oracle9i的init.ora参数中文说明

    可以使用 NLS_COMP 指定必须根据NLS_SORT 会话参数进行语言比较。 值范围: Oracle8i National Language Support Guide 中指定的任何有效的10 字节字符串。 默认值: BINARY nls_currency: 说明: 为 L 数字格式...

    PHP 代码自动生成工具 e-World Tech PHPMaker 2020.0.3 英文特别免费版.rar

    Oracle sort – 用于设置Oracle的NLS_SORT参数 自动填充原始值 – 对于自动填充原始(数据库)值而不是查找值 多文件上载分隔符 – 指定用于分隔文件名的文件上载分隔符 将Colorbox用于图像 使用响应式布局 使用移动...

    ORACLE精品脚本笔记

    监控内存和硬盘的排序比率,最好使它小于 .10,增加 sort_area_size <br>SELECT name, value FROM v$sysstat WHERE name IN ('sorts (memory)', 'sorts (disk)'); <br> 12. 监控当前数据库谁在运行什么...

    softap_ap6212a0_tinav2.1_验证通过_旧版本的系统_20170915_1223没有外层目录.7z

    旧版本版本的全志R16平台的tinav2.1的系统打开softAP 2017/9/14 17:25 版本:V1.0 1、原始编译: ...rootroot@cm-System-Product-Name:~$ cd /home/wwt/ ...rootroot@cm-System-Product-Name:/home/wwt$ tar zxvf...

    Oracle事例

    1.增加主键 alter table TABLE_NAME add constraint KEY_NAME primary key (TABLE_COLUMN); 指定表空间 alter table TABLE_NAME add constraint KEY_NAME primary key (TABLE_COLUMN) using index tablespace ...

    eclipse 格式化模板

    eclipse 的code style 下的cleanup 格式化模板 ...Sort members excluding fields, enum constants, and initializers Organize imports Format source code Correct indentation Remove redundant type arguments

    用c描述的数据结构演示软件

    递归工作栈中含调用语句行号 adr、变参 nls 和值参 ls。 15. 创建广义表的存储结构 图示窗口显示广义表存储结构的建立过程和算法执行过程中参数Sub的当前值。 16. 遍历二叉树 图示窗口显示二叉树的逻辑结构和遍历...

    数据结构演示软件

    递归工作栈中含调用语句行号 adr、变参 nls 和值参 ls。 15. 创建广义表的存储结构 图示窗口显示广义表存储结构的建立过程和算法执行过程中参数Sub的当前值。 16. 遍历二叉树 图示窗口显示二叉树的逻辑结构和...

    c语言数据结构算法演示(Windows版)

    递归工作栈中含调用语句行号 adr、变参 nls 和值参 ls。 15. 创建广义表的存储结构 图示窗口显示广义表存储结构的建立过程和算法执行过程中参数Sub的当前值。 16. 遍历二叉树 图示窗口显示二叉树的逻辑结构和遍历...

Global site tag (gtag.js) - Google Analytics