Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 甲骨文按字母顺序排序上A,下A,数字_Sql_Oracle_Sql Order By - Fatal编程技术网

Sql 甲骨文按字母顺序排序上A,下A,数字

Sql 甲骨文按字母顺序排序上A,下A,数字,sql,oracle,sql-order-by,Sql,Oracle,Sql Order By,我使用Oracle版本12和以下NLS参数进行排序 NLS_语言美语 NLS_排序二进制文件 NLS_COMP二进制文件 例如,“安迪”、“安迪”、“安迪”、“安迪”、“亚伦”、“鲍勃” 按姓名从员工订单中选择姓名 结果: “Andy”、“Andy”、“Aaron”、“Andy”、“Bob”、“Andy” 如果我将NLS_排序更改为WEST_EUROPEAN,则应为“1安迪”、“安迪”、“艾伦”、“安迪”、“安迪”、“鲍勃” 但结果是“1安迪”、“安迪”、“安迪”、“艾伦”、“安迪”、“鲍勃

我使用Oracle版本12和以下NLS参数进行排序

  • NLS_语言美语
  • NLS_排序二进制文件
  • NLS_COMP二进制文件
例如,“安迪”、“安迪”、“安迪”、“安迪”、“亚伦”、“鲍勃”

按姓名从员工订单中选择姓名

结果: “Andy”、“Andy”、“Aaron”、“Andy”、“Bob”、“Andy”

如果我将NLS_排序更改为WEST_EUROPEAN,则应为“1安迪”、“安迪”、“艾伦”、“安迪”、“安迪”、“鲍勃” 但结果是“1安迪”、“安迪”、“安迪”、“艾伦”、“安迪”、“鲍勃” 安迪即使是小写也在中间。

按NLSSORT从员工订单中选择姓名(姓名,'NLS_SORT=WEST_EUROPEAN')


首先,您可以通过在排序规则规范:west\u european\u ci中添加_ci来实现不区分大小写的排序。也就是说,在西欧排序规范中,数字排在字母后面。以下是我使用不同的排序规则规范获得的数据

SQL> with dt as (
  2  select ' 1Andy' cv from dual
  3  union all
  4  select ' Andy' from dual
  5  union all
  6  select '1Andy' from dual
  7  union all
  8  select 'Andy' from dual
  9  union all
 10  select 'andy' from dual
 11  union all
 12  select 'Aaron' from dual
 13  union all
 14  select 'Bob' from dual)
 15  select *
 16  from dt
 17  order by cv;

CV    
------
 1Andy
 Andy
1Andy
Aaron
Andy
Bob
andy

7 rows selected. 

SQL> 
SQL> with dt as (
  2  select ' 1Andy' cv from dual
  3  union all
  4  select ' Andy' from dual
  5  union all
  6  select '1Andy' from dual
  7  union all
  8  select 'Andy' from dual
  9  union all
 10  select 'andy' from dual
 11  union all
 12  select 'Aaron' from dual
 13  union all
 14  select 'Bob' from dual)
 15  select *
 16  from dt
 17  order by nlssort(cv,'NLS_SORT=WEST_EUROPEAN');

CV    
------
 Andy
 1Andy
Aaron
Andy
andy
Bob
1Andy

7 rows selected. 

SQL> 
SQL> with dt as (
  2  select ' 1Andy' cv from dual
  3  union all
  4  select ' Andy' from dual
  5  union all
  6  select '1Andy' from dual
  7  union all
  8  select 'Andy' from dual
  9  union all
 10  select 'andy' from dual
 11  union all
 12  select 'Aaron' from dual
 13  union all
 14  select 'Bob' from dual)
 15  select *
 16  from dt
 17  order by nlssort(cv,'NLS_SORT=WEST_EUROPEAN_ci');

CV    
------
 Andy
 1Andy
Aaron
Andy
andy
Bob
1Andy

7 rows selected.