使用 (Oracle) SQL 对字符串中的分隔值进行排序
假设你有有
select '9|2|6|7|5' as somedata from dual
没有一种方法可以让我做这样的事情:
select
in_string_sort('|', a.somedata)
from
(select '9|2|6|7|5' as somedata from dual) a
所以结果是 '2|5|6|7|9'
?
我知道,我可以使用一个函数来实现这一点,但这太基本了,我想知道 Oracle 是否会有一些内置函数来处理这类事情。
[编辑]忘记提及:这将在 Oracle 10gR2 中出现。
Say you have
select '9|2|6|7|5' as somedata from dual
Is there a way where I could do something like:
select
in_string_sort('|', a.somedata)
from
(select '9|2|6|7|5' as somedata from dual) a
So the result would be '2|5|6|7|9'
?
I know, I could use a function to get that, but this is so basic I was wondering if Oracle would have some built-in function for this sort of thing.
[EDIT] forgot to mention: this would be in Oracle 10gR2.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
据我所知没有这样的内置功能。你没有说哪个版本,所以我假设11g。这个查询应该为你做:
So far as I know there is no such built-in function. You don't say which version, so I'll assume 11g. This query should do it for you:
这是一个较旧的问题,但我遇到它来寻找我的特定问题的解决方案。 RichardJQ 的答案很好,但它只适用于单个字符字段(长度为 1)和数字。此外,我想简化解决方案以使用较新版本的 Oracle 中提供的正则表达式函数。以下代码片段适用于具有任何字符长度和字母数字值的字段。该解决方案适用于 11g 或更高版本。
This is an older question but I ran across it searching for a solution to my particular problem. The answer from RichardJQ is good but it only worked for single char fields (length of 1) and numeric digits. In addition, I wanted to simplify the solution to use regexp functions available in newer versions of Oracle. The following snippet will work for fields with any char length and alphanumeric values. This solution works with 11g or newer.