• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • MsSql
  • Mysql
  • oracle
  • MariaDB
  • DB2
  • SQLite
  • PostgreSQL
  • MongoDB
  • Redis
  • Access
  • 数据库其它
  • sybase
  • HBase
您的位置:首页 > 数据库 >Mysql > Oracle的NLS_COMP和NLS_SORT参数

Oracle的NLS_COMP和NLS_SORT参数

作者:匿名 字体:[增加 减小] 来源:互联网 时间:2018-12-05

匿名通过本文主要向大家介绍了Oracle,NLS,COMP,SORT,参数,NLS,CO等相关知识,希望本文的分享对您有所帮助

NLS_COMP和NLS_SORT参数 Oracle默认是采用binary进行排序,这对于例如中文的排序来说,是不恰当的。 使用这两个参数可以指定排序的方法,比如拼音或是,要注意可能会引起性能问题。 解决方法是使用NLSSORT函数来建立一个函数索引。 NLS_COMP = { BINARY | LIN

NLS_COMP和NLS_SORT参数
Oracle默认是采用binary进行排序,这对于例如中文的排序来说,是不恰当的。
使用这两个参数可以指定排序的方法,比如拼音或是,要注意可能会引起性能问题。
解决方法是使用NLSSORT函数来建立一个函数索引。

NLS_COMP = { BINARY | LINGUISTIC | ANSI }
-


BINARY
Normally, comparisons in the WHERE clause and in PL/SQL blocks is binary unless you specify theNLSSORT function.
LINGUISTIC
Comparisons for all SQL operations in the WHERE clause and in PL/SQL blocks should use the linguistic sort specified in theNLS_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 setNLS_COMP to LINGUISTIC


NLS_SORT = { BINARY | linguistic_definition}
NLS_SORT specifies the collating sequence for character value comparison in various SQL operators and clauses, for example, 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/or telephone directories in those languages.

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.

下面做个测试:
首先来看看可用的中文排序方法:
select value from v$nls_valid_values where parameter='SORT' and value like '%SCHINESE%';
返回可用的中文排序方法
SCHINESE_PINYIN_M -- 按照拼音排序
SCHINESE_STROKE_M -- 按照笔划(第一顺序)、部首(第二顺序)排序
SCHINESE_RADICAL_M -- 按照部首(第一顺序)、笔划(第二顺序)排序

下面来做测试。
create index emp_ename_idx on emp(ename);
现在察看select * from emp where ename='Mike';的执行计划,
explain plan for select * from emp where ename='Mike';
select * from table(dbms_xplan.display);
可以看到Oracle会走索引emp_ename_idx。

1.---------------------------------------------------------------------------------------------
2.| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | 3.--------------------------------------------------------------------------------------------- 4.| 0 | SELECT STATEMENT | | 1 | 46 | 2 (0)| 00:00:01 | 5.| 1 | TABLE ACCESS BY INDEX ROWID| EMP | 1 | 46 | 2 (0)| 00:00:01 | 6.|* 2 | INDEX RANGE SCAN | EMP_ENAME_IDX | 1 | | 1 (0)| 00:00:01 | 7.--------------------------------------------------------------------------------------------- 8.
9.Predicate Information (identified by operation id): 10.--------------------------------------------------- 11.
12. 2 - access("ENAME"=U'Mike') alter session set nls_comp='LINGUISTIC';
alter session set nls_sort='SCHINESE_PINYIN_M';
之后再查看执行计划,得到结果:
1.--------------------------------------------------------------------------
2.| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | 3.-------------------------------------------------------------------------- 4.| 0 | SELECT STATEMENT | | 1 | 46 | 3 (0)| 00:00:01 | 5.|* 1 | TABLE ACCESS FULL| EMP | 1 | 46 | 3 (0)| 00:00:01 | 6.-------------------------------------------------------------------------- 7.
8.Predicate Information (identified by operation id): 9.--------------------------------------------------- 10.
11. 1 - filter(NLSSORT("ENAME",'nls_sort=''SCHINESE_PINYIN_M''')=HEXTORAW 12. ('0230021B022301FE0000020202020007020202') ) 可以看到,现在走全表扫描了。
接下来,如果创建如下的索引
create index emp_ename_idx_nlssort on emp(nlssort(ename,'NLS_SORT=SCHINESE_PINYIN_M'));
再查看执行计划,发现又走索引emp_ename_idx_nlssort了。
1.-----------------------------------------------------------------------------------------------------
2.| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | 3.----------------------------------------------------------------------------------------------------- 4.| 0 | SELECT STATEMENT | | 1 | 46 | 2 (0)| 00:00:01 | 5.| 1 | TABLE ACCESS BY INDEX ROWID| EMP | 1 | 46 | 2 (0)| 00:00:01 | 6.|* 2 | INDEX RANGE SCAN | EMP_ENAME_IDX_NLSSORT | 1 | | 1 (0)| 00:00:01 | 7.----------------------------------------------------------------------------------------------------- 8.
9.Predicate Information (identified by operation id): 10.--------------------------------------------------- 11.
12. 2 - access(NLSSORT("ENAME",'nls_sort=''SCHINESE_PINYIN_M''')=HEXTORAW('0230021B022301FE000 13. 0020202020007020202') )
分享到:QQ空间新浪微博腾讯微博微信百度贴吧QQ好友复制网址打印

您可能想查找下面的文章:

  • 浅析drop user与delete from mysql.user的区别
  • mysql prompt的用法详解
  • 如何使用索引提高查询速度
  • 深入mysql创建自定义函数与存储过程的详解
  • JDBC数据库的使用操作总结
  • MySQL查询优化:LIMIT 1避免全表扫描提高查询效率
  • MySQL与Oracle的语法区别详细对比
  • 有关mysql中ROW_COUNT()的小例子
  • MySQL 百万级分页优化(Mysql千万级快速分页)
  • 从创建数据库到存储过程与用户自定义函数的小感

相关文章

  • 2018-12-05mysql进阶(二十四)防御SQL注入的方法总结
  • 2018-12-05Mysql的游标的定义使用及关闭深入分析
  • 2018-12-05MySQL 存储过程的基本用法介绍
  • 2017-05-11mysql中max_allowed_packet参数的配置方法(避免大数据写入或者更新失败)
  • 2018-12-05 SQL Server存储过程的编写和优化方法
  • 2018-12-05分享在Linux命令下操作MySQL视图实例代码
  • 2017-05-11Mysql中实现提取字符串中的数字的自定义函数分享
  • 2017-05-11mysql source 命令导入大的sql文件的方法
  • 2018-12-05MySQL如何设置慢查询日志?
  • 2018-12-05Mysql数据库中varchar类型转化为int类型的方法介绍

文章分类

  • MsSql
  • Mysql
  • oracle
  • MariaDB
  • DB2
  • SQLite
  • PostgreSQL
  • MongoDB
  • Redis
  • Access
  • 数据库其它
  • sybase
  • HBase

最近更新的内容

    • SQLServer 设置单词首字母大写
    • MySQL查询优化:用子查询代替非主键连接查询实例介绍
    • mysql中的主键递增
    • 一步一步教你网站同步镜像(转载)
    • SQLserver查询数据类型为ntext是空或NULL值的方法
    • MySQL服务在Windows下无法停止和删除的解决办法详解
    • 在Linux下安装Oracle
    • Mysql存储程序、函数、触发程序及复制:常见问题
    • MySQL中按照多字段排序及问题解决
    • processlist命令 查看mysql 线程

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有