Sql 甲骨文按字母顺序排序上A,下A,数字
我使用Oracle版本12和以下NLS参数进行排序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安迪”、“安迪”、“安迪”、“艾伦”、“安迪”、“鲍勃
- NLS_语言美语
- NLS_排序二进制文件
- NLS_COMP二进制文件
首先,您可以通过在排序规则规范: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.