Split string in Oracle with regexp_substr in order(使用 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 中的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 regexp_substr 按顺序拆分 Oracle 中的字符串
- 导入具有可变标题的 Excel 文件 2021-01-01
- SQL 临时表问题 2022-01-01
- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01
- 在SQL中,如何为每个组选择前2行 2021-01-01
- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
- 更改自动增量起始编号? 2021-01-01
- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01
- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01
