[英]How to split string using a matching string in Oracle using regexp?
Currently I've this, but it is returning null
. 目前,我有这个,但它返回
null
。
select regexp_substr( 'abcx1bcdx2mno', '[^x[[:digit:]]]+', 1,1 ) from dual;
select regexp_substr( 'abcx1bcdx2mno', '[^x[[:digit:]]]+', 1,1 ) from dual;
I want to have it such a way, that the first query returns abc
, and second one returns bcd
. 我想要这样一种方式,第一个查询返回
abc
,第二个查询返回bcd
。
Unfortunately we cannot negate a group of characters(search string). 不幸的是,我们不能否定一组字符(搜索字符串)。 As a workaround we could replace our search string with a single character, space for example, and then negate that one character:
作为一种解决方法,我们可以将搜索字符串替换为单个字符(例如空格),然后取反一个字符:
Here is a simple example: 这是一个简单的示例:
with t1(col) aS(
select 'abcx1bcdx2mno' from dual
)
select regexp_substr( regexp_replace(col, 'x[[:digit:]]', ' '), '[^ ]+'
, 1, level) as res
from t1
connect by level <= regexp_count( regexp_replace(col, 'x[[:digit:]]', ' ')
, '[^ ]+')
Note : regexp_count()
regular expression function introduced in oracle 11g version. 注意 :oracle 11g版本中引入了
regexp_count()
正则表达式函数。
Result: 结果:
RES
-------------
abc
bcd
mno
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.