oracle查询显示小写,oracle查询区分大小写

ORACLE默认所存的值是取分大小写的,但有些需求想忽略大小写,今天就浅谈一下nls_sort ,nls_comp实现查询忽略大小写查询

anbob@ORCL>select*fromtestci ;

IDNAMEREMARK

---------- -------------------- --------------------

1 alowercode

1 Auppercode

anbob@ORCL>select*fromtestciwherename='a';

IDNAMEREMARK

---------- -------------------- --------------------

1 alowercode

anbob@ORCL>select*fromv$nls_parameterswhereparameter ='NLS_SORT';

PARAMETER                         VALUE

-------------------------------- ----------------

NLS_SORTBINARY

anbob@ORCL>ALTERSESSIONSETNLS_SORT='BINARY_CI';

Session altered.

anbob@ORCL>select*fromtestciwherename='a';

IDNAMEREMARK

---------- -------------------- --------------------

1 alowercode

anbob@ORCL>select*fromv$nls_parameterswhereparameter ='NLS_COMP';

PARAMETER                         VALUE

---------------------------------- ------------------

NLS_COMPBINARY

anbob@ORCL>ALTERSESSIONSETNLS_COMP=LINGUISTIC;

Session altered.

anbob@ORCL>select*fromtestciwherename='a';

IDNAMEREMARK

---------- -------------------- --------------------

1 alowercode

1 Auppercode

anbob@ORCL> select * from testci ;

ID NAME REMARK

---------- -------------------- --------------------

1 a lower code

1 A upper code

anbob@ORCL> select * from testci where name='a';

ID NAME REMARK

---------- -------------------- --------------------

1 a lower code

anbob@ORCL> select * from v$nls_parameters where parameter ='NLS_SORT';

PARAMETER VALUE

-------------------------------- ----------------

NLS_SORT BINARY

anbob@ORCL> ALTER SESSION SET NLS_SORT='BINARY_CI';

Session altered.

anbob@ORCL> select * from testci where name='a';

ID NAME REMARK

---------- -------------------- --------------------

1 a lower code

anbob@ORCL> select * from v$nls_parameters where parameter ='NLS_COMP';

PARAMETER VALUE

---------------------------------- ------------------

NLS_COMP BINARY

anbob@ORCL> ALTER SESSION SET NLS_COMP=LINGUISTIC;

Session altered.

anbob@ORCL> select * from testci where name='a';

ID NAME REMARK

---------- -------------------- --------------------

1 a lower code

1 A upper code

NLS_COMP:

确定数据库中值的比较,10G中增加了LINGUISTIC,根据nls_sort参数指定进行比较,用来取代ansi,但ANSI为了向后兼容保留,还有一个值是BINARY根据字符的二进制值比较也是默认值,总共三个值

note:To improve the performance, you can also define a linguistic index on the column for which you want linguistic comparisons.

nls_sort:

指定order by 的查询顺序,If the value is BINARY, then the collating sequence for ORDER BY queries is based on the numeric value of characters.

note: 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.

值非常多,可以通过V$NLS_VALID_VALUES where parameter=’SORT’ 查询

不过修改任何参数都要考虑性能问题

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. 因篇幅原因 就说这些,其实与这两个参数相关的还有很多…

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值