select regexp_substr('444.555.666', '[^.]+', 1, level) col
from dual
connect by level <= regexp_count('444.555.666', '\.') + 1
输出结果:
COL
----
444
555
666
多行拆分
如果数据表存在多行数据需要拆分,也可以在原表上使用connect+正则的方法:
方法一
with t as
(select '111.222.333' col
from dual
union all
select '444.555.666' col
from dual)
select regexp_substr(col, '[^.]+', 1, level)
from t
connect by level <= regexp_count(col, '\.\') + 1
and col = prior col
and prior dbms_random.value > 0
结果:
---------
111
222
333
444
555
666
方法二
使用构造的最大行数值关联原表:
with t as
(select '111.222.333' col
from dual
union all
select '444.555.666' col
from dual)
select regexp_substr(col, '[^.]+', 1, lv)
from t, (select level lv from dual connect by level < 10) b
where b.lv <= regexp_count(t.col, '\.\') + 1
with t as
(select '111.222.333' col
from dual
union all
select '444.555.666' col
from dual)
select column_value
from t,
table(cast(multiset
(select regexp_substr(col, '[^.]+', 1, level) dd
from dual
connect by level <= regexp_count(t.col, '\.\') + 1) as
sys.odcivarchar2list)) a
with t as
(select '111.222.333' col
from dual
union all
select '444.555.666' col
from dual)
select regexp_substr(col, '[^.]+', 1, trim(column_value))
from t,
xmltable(concat('1 to ',regexp_count(t.col, '\.\') + 1)) a ;