Oracle ORDER BY 中忽略与号 (&) 字符
我正在 Oracle 中运行一个查询,该查询按可能包含带有“&”号的值的列排序。然而,排序算法似乎忽略了&符号。
例如:
select * from (
select '&' txt from dual
union
select 'P' txt from dual
union
select 'N' txt from dual
)
order by txt
准确打印(我猜是正确的):
&
N
P
但是,如果我用 '&' 更改文本到 '&Z',结果改变:
select * from (
select '&'||'Z' txt from dual // concatenating just to
// avoid variable substitution
union
select 'P' txt from dual
union
select 'N' txt from dual
)
order by txt
结果是:
N
P
&Z
如果我把 'Z' 改成 'A' 那么结果是:
&A
N
P
看来 '&' ORDER BY 子句不考虑该情况。有谁知道这是否是预期行为或者我是否缺少某些配置步骤?我知道需要转义&符号以进行插入或更新。但问题是该角色已经在表中了!
预先感谢各位。
I am running a query in Oracle and that query is ordered by a column that may have values with ampersand. However, it seems that ampersand is being ignored by the sorting algorithm.
For instance:
select * from (
select '&' txt from dual
union
select 'P' txt from dual
union
select 'N' txt from dual
)
order by txt
Prints exactly (and correctly, I guess):
&
N
P
However, if I change the text with '&' to '&Z', the result changes:
select * from (
select '&'||'Z' txt from dual // concatenating just to
// avoid variable substitution
union
select 'P' txt from dual
union
select 'N' txt from dual
)
order by txt
Result is then:
N
P
&Z
If I change 'Z' to 'A' then the result is:
&A
N
P
It seems that the '&' is not being considered by ORDER BY clause. Does anyone know if this is expected behavior or if I am missing some configuration step? I understand that one needs to escape ampersand for inserts or updates. But thing is that the character is already in the table!
Thanks in advance, guys.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是语言排序的效果:
它确实对您要排序的语言产生影响。有些字符根据其语言而具有不同的值。对于二进制,您可以使用 ascii 值进行排序。
It is the effect of linguistic sorting:
It does make a difference for what language you are sorting. Some characters have different values depending on their language. With binary you sort using the ascii values.
这可能取决于您的 NLS_LANGUAGE 和 NLS_SORT 设置。
我在 Oracle 10g 上得到以下信息,其中 NLS_LANGUAGE =
AMERICAN
和 NLS_SORT = (null)。It may depend on your NLS_LANGUAGE and NLS_SORT setting.
I get the following on Oracle 10g, with NLS_LANGUAGE =
AMERICAN
and NLS_SORT = (null).