with table1 as(
select 'code1' code,
'2451020 2451130 2541420 2541220 2541230 2541241 2541231 2541230' str
from dual
union all
select 'code2' code,
'2451020 2451120 2541425 2541220 2541225 2541260 2541238 2541230' str
from dual
),
table2 as(
SELECT DISTINCT code, regexp_substr(str, '[^ ]+', 1, LEVEL) str
FROM table1
CONNECT BY LEVELselect * from table1;
CODESTR
----- ---------------------------------------------------------------
code1 2451020 2451130 2541420 2541220 2541230 2541241 2541231 2541230
code2 2451020 2451120 2541425 2541220 2541225 2541260 2541238 2541230
SQL>
SQL> select code,
2 str,
3 flag "level(结尾尾数)",
4 count(*) "countNum"
5from
6(select a.rn,
7
b.code,
8
b.str,
9
substr(substr(' ' || str || ' ',
10
instr(' ' || str || ' ', ' ', 1, a.rn) + 1,
11
instr(' ' || str || ' ', ' ', 1, a.rn + 1) - instr(' ' || str || ' ', ' ', 1, a.rn) - 1),
12
-2) flag
13 from (select level rn from (select max(length(str) - length(replace(str, ' ', ''))) diff from table1) connect by level = a.rn)
16 group by code, str, flag
17 order by code, str, flag
18/
CODESTR
level(结尾尾数) countNum
----- --------------------------------------------------------------- --------------- ----------
code1 2451020 2451130 2541420 2541220 2541230 2541241 2541231 2541230 20
3
code1 2451020 2451130 2541420 2541220 2541230 2541241 2541231 2541230 30
3
code1 2451020 2451130 2541420 2541220 2541230 2541241 2541231 2541230 31
1
code1 2451020 2451130 2541420 2541220 2541230 2541241 2541231 2541230 41
1
code2 2451020 2451120 2541425 2541220 2541225 2541260 2541238 2541230 20
3
code2 2451020 2451120 2541425 2541220 2541225 2541260 2541238 2541230 25
2
code2 2451020 2451120 2541425 2541220 2541225 2541260 2541238 2541230 30
1
code2 2451020 2451120 2541425 2541220 2541225 2541260 2541238 2541230 38
1
code2 2451020 2451120 2541425 2541220 2541225 2541260 2541238 2541230 60
1
9 rows selected
|