使用 regexp_substr 按顺序拆分 Oracle 中的字符串 [英] Split string in Oracle with regexp_substr in order

查看:71
本文介绍了使用 regexp_substr 按顺序拆分 Oracle 中的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Oracle 数据库中有一个字符串,我的字符串是:'bbb;aaa;qqq;ccc'

I have a string in Oracle database, my string is: 'bbb;aaa;qqq;ccc'

我使用正则表达式来分割我的字符串:

I used regexp for split my string:

select distinct trim(regexp_substr('bbb;aaa;qqq;ccc','[^;]+', 1,level) ) as q 
from dual
connect by regexp_substr('bbb;aaa;qqq;ccc', '[^;]+', 1, level) is not null ;

我想按顺序拆分它,我希望总是以下输出:

I want to split it in order, I expected the below output always:

bbb
aaa
qqq
ccc

因为 subString 的顺序对我来说非常重要.但是这个查询的结果不是有序的:

because order of the subString are very important for me. but the result of this query is not in order:

qqq
aaa
bbb
ccc

推荐答案

您不需要 DISTINCT 即可获得结果;此外,要以给定的顺序获得结果,您只需要一个 ORDER BY 子句:

You don't need a DISTINCT to get your result; besides, to get the result in a given order, all you need is an ORDER BY clause:

select trim(regexp_substr('bbb;aaa;qqq;ccc','[^;]+', 1,level) ) as q 
from dual
connect by regexp_substr('bbb;aaa;qqq;ccc', '[^;]+', 1, level) is not null
order by level

这篇关于使用 regexp_substr 按顺序拆分 Oracle 中的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆