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 中的字符串
基础教程推荐
- 无法解决整理冲突 2021-01-01
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
- 是否可以执行按位分组功能? 2021-01-01
- 在 SQL 中连接多个表 2021-01-01
