nls_comp和nls_sort

Oracle官方文档Globalization Support的Linguistic Sorting and String Searching一章有详细解释

nls_sort: 决定了Oracle 排序的方法,影响了ORDER BY, GROUP BY, comparison =, <>, <=, >=, IN, BETWEEN, LIKE, MIN/MAX, GREATEST/LEAST, INSTR等函数/操作符。

语法:NLS_SORT = { BINARY | sort_name }

Binary是默认值。

Linguistic sort(非Binary)时,常规的B-tree索引将不被采用。这时需要建一个基于NLSSORT函数的索引。官方文档里有sort_name的列表。

假如需要做不区分大小写的sort/比较,在sort_name后加_CI。如:

alter session set nls_sort=binary_ci;
nls_comp: 决定比较的方法。

语法:NLS_COMP = { BINARY | LINGUISTIC | ANSI }

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

客户端的JDBC驱动,OCI驱动,NLS_LANG环境变量设置将会覆盖服务器端这两个参数的设置。

例子1:大小写不区分, NLS_COMP=ANSI仅作用于少数操作符/函数,不适用于like及min(), max()等大多数函数。

truncate table t1;
alter session set nls_sort=binary_ci;
alter session set nls_comp=ansi;
insert into t1 values(99, 'Wu');
insert into t1 values(1,'wu');
commit;
select * from t1 where name='wu';
        ID NAME                                                                                               
---------- ----------------------------------------------------------------------------------------------------
        99 Wu                                                                                                   
         1 wu  
select * from t1 where name like 'w%';
        ID NAME                                                                                               
---------- ----------------------------------------------------------------------------------------------------
         1 wu 
 

例子2: 大小写不区分, NLS_COMP='linguistic',适用于所有操作符/函数

alter session set nls_comp='linguistic';
select * from t1 where name like 'w%';
session SET altered.

        ID NAME                                                                                               
---------- ----------------------------------------------------------------------------------------------------
        99 Wu                                                                                                   
         1 wu                                                                                                  
 
NLSSort()函数

select name, nlssort(name, 'nls_sort=binary_ci') from t1;
NAME                                                                                                 NLSSORT(NAME,'NLS_SORT=BINARY_CI')                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 
---------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Wu                                                                                                   0077007500                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           
wu                                                                                                   0077007500       

该函数返回Raw数据类型,Raw最大长度2000字节。



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值