甲骨文 - 首先按字母排序然后数字
我想按下面介绍的顺序对以下数据项进行排序 (然后数字):
AA
AB
AC
..
00
01
02
..
99
但是,我的查询 - 基于ASCII代码的xxxxx ASC的订单 - 它首先检索所有数字,然后用如图所示的字母检索:
00
01
..
99
AA
AB
..
ZZ
任何技巧以使其更适当地进行排序?
谢谢!
I want to sort the following data items in the order they are presented below
( letters then numbers ) :
AA
AB
AC
..
00
01
02
..
99
However, my query - using Order by xxxxx ASC - based on ASCII code - which retrieves all numbers first and then letters as shown :
00
01
..
99
AA
AB
..
ZZ
Any tricks to make it sort more appropriately?
THANKS!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
一种做到这一点的方法是,在情况下使用情况和使用常规订购的情况下使用案例对项目的订购优先级。这样的优先级将在字母内进行,然后是数字,然后在相应类别中订购
:
https://dbfiddle.uk/?rdbms=oracle_11.2&; fiddle = dff7E6805F1B59501D59CB91194CF1A0
One way to do this would be to prioritize the ordering of items by alphabets using case when condition and after that to use the regular ordering. This way the priority sort would be on alphabets then numbers, followed by ordering within the respective categories
Eg:
https://dbfiddle.uk/?rdbms=oracle_11.2&fiddle=dff7e6805f1b59501d59cb91194cf1a0
另一个选项是使用正则表达式,以便先排序数字,然后将其余的(“休息”是字母):
对于相对较小的数据集,这是可以的,但是 - 正则表达式似乎有些slow> slow 当我们必须使用大型数据集时,请查看是否有帮助。
Another option is to use regular expressions so that digits are sorted first, then the rest (and that "rest" will be letters):
That's OK for relatively small data sets, but - regular expressions seem to be somewhat slow when we have to work with large data sets so - see if it helps.
您也可以使用正则表达式实现“ \ d”匹配任何非数字的情况。
You can also use a regular expression to achieve the same where '\D' will match any non-digit.