我正在使用以下 NLS 参数对 Oracle 版本 12 进行排序
例如。 “1安迪”、“安迪”、“安迪”、“安迪”、“亚伦”、“鲍勃”
<块引用>按姓名从员工订单中选择姓名
结果: “1安迪”、“安迪”、“亚伦”、“安迪”、“鲍勃”、“安迪”
如果我将 NLS_SORT 更改为 WEST_EUROPEAN,则假定为“1Andy”、“Andy”、“Aaron”、“Andy”、“andy”、“Bob” 但结果是“1Andy”、“Andy”、“andy”、“Aaron”、“Andy”、“Bob” 即使是小写的 andy 也放在中间。
<块引用>按 NLSSORT(name ,'NLS_SORT=WEST_EUROPEAN') 从员工订单中选择姓名
答案 0 :(得分:1)
首先,您可以通过在排序规则中添加 _ci 来实现不区分大小写的排序:west_european_ci。话虽如此,似乎在 west_european 排序规范中,数字在 alpha 字符之后。这是我使用不同整理规范获得的数据
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.