정규 표현 식 regexpsubstr
3727 단어 Development
regexp_substr
①select regexp_substr(string, '[^,]+', 1, level)
from dual
connect by level <= regexp_count(string, '[^,]+')
and rowid = prior (rowid)
and (prior dbms_random.value) is not null;
②select regexp_substr(string, '[^,]+', 1, level)
from dual
connect by level <= length(string) - LENGTH(REPLACE(string, ',', '')) + 1
and rowid = prior (rowid)
and (prior dbms_random.value) is not null;
REGEXP_SUBSTR ,
( ) , ,level,connect ,
- = +1
Test1: : N1 N2 , N1 , N2
N1:
:
SQL> select regexp_substr('i,am,a,pretty,girl', '[^,]+', 1, level) substring
2 from dual
3 connect by level <= regexp_count('i,am,a,pretty,girl', '[^,]+')
4 ;
SUBSTRING
------------------------------------------------------------------------
i
am
a
pretty
girl
,
create table ta as
select 'i,am,a,pretty,girl' substring
from dual
union all
select '1,2,3,4,5,6'
from dual
union all
select ' , , , '
from dual;
SQL> select count(regexp_substr(substring, '[^,]+', 1, level)) cnt
2 from ta
3 connect by level <= regexp_count(substring, '[^,]+')
4 ;
CNT
----------
444
N2:( N1 dbms_random.value)
:
SQL> select regexp_substr('i,am,a,pretty,girl', '[^,]+', 1, level)substring1
2 from dual
3 connect by level <= regexp_count('i,am,a,pretty,girl', '[^,]+')
4 and rowid = prior (rowid)
5 and (prior dbms_random.value) is not null;
SUBSTRING1
------------------------------------------------------------------------
i
am
a
pretty
girl
SQL> select count(regexp_substr(substring, '[^,]+', 1, level)) cnt
2 from ta
3 connect by level <= regexp_count(substring, '[^,]+')
4 and rowid = prior (rowid)
5 and (prior dbms_random.value) is not null;
CNT
----------
15
Test2:
SQL> SELECT REGEXP_SUBSTR('1 meeting you,2 waiting for you.7',
2 '[0-9]+',
3 1,
4 level)
5 FROM dual
6 connect by level <=
7 regexp_count('1 meeting you,2 waiting for you.7', '[0-9]+');
REGEXP_SUBSTR('1MEETINGYOU,2WA
--------------------------------------------------------------------------------
1
2
7
Test3: REGEP_SUBSTR
SQL> SELECT REGEXP_SUBSTR('u are best best ', '([[:alnum:]]+)([[:space:]]+)\1') AS substr
2 FROM dual;
SUBSTR
---------
best best
Test4:IP 0
select listagg(tring1) within group(order by rn) tring
from (select rn, lpad(tring, 3, 0) tring1
from (select level rn,
regexp_substr('12.34.6.110', '[^.]+', 1, level) tring
from dual
connect by level <= 4));
TRING
--------------------------------------------------------------------------------
012034006110