NLS_SORT设置
2012-08-15 14:00
351 查看
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.
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.
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视图中找
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 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 |
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视图中找
相关文章推荐
- 小心NLS_SORT和NLS_COMP的设置成为性能杀手
- NLS_SORT和NLS_COMP的设置影响性能
- 小心NLS_SORT和NLS_COMP的设置成为性能杀手
- 小心NLS_SORT和NLS_COMP的设置成为性能杀手
- 小心NLS_SORT和NLS_COMP的设置成为性能杀手
- 【转】 小心NLS_SORT和NLS_COMP的设置成为性能杀手
- Oracle数据库按中文拼音排序问题,NLS_SORT设置
- Oracle中NLS_LANG参数设置
- 浅析NLS_COMP、NLS_SORT(三)
- Oracle 客户端 NLS_LANG 的设置(转)
- Oracle NLS_LANG设置
- nls_sort和nlssort 排序功能介绍
- Oracle中NLS_LANG的默认值(用于oracle字符集[客户端|操作系统|服务器端]设置)
- 关于NLS_DATE_FORMAT的设置
- 浅析NLS_SORT、NLS_COMP(-)
- Oracle数据库当前的nls_date_format参数值查询及设置
- 设置Oracle PL/SQL 时间显示格式 NLS_TIMESTAMP_FORMAT 2008-01-27 00:04:35:877000
- 设置sort_buffer_size
- Oracle数据库当前的nls_date_format参数值查询及设置
- oracle客户端NLS_LANG设置