|
我实在是闲的蛋疼,周五不怎么又扫到了这个帖子,看到自己说了20行以内搞定。。。
回头翻楼,发现没有比我“短”的,争取保住又快又短。。。
这个超长substr是硬伤,但是还是没想到怎么用regexp_substr或者replace来搞定
with t as (
select round(2.5-level) pos, to_char(ceil(level/2)) c
from dual
connect by level<=4
),
r (s, x_pos, path) as (
select '222x111' s, 4, ''
from dual
union all
select substr(replace(r.s, 'x', t.c), 1, x_pos+t.pos-1)||'x'||substr(replace(r.s, 'x', t.c), x_pos+t.pos+1), x_pos+t.pos, path||to_char(x_pos+t.pos)||'#'
from t, r
where 1=1
and substr(r.s, x_pos+t.pos, 1)=t.c
and x_pos+t.pos between 1 and 7
)
select *
from r
where s='111x222';
|
|