使用regexp_substr在Oracle中拆分字符串 [英] Split string in Oracle with regexp_substr in order

查看:89
本文介绍了使用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天全站免登陆