really?
ops$tkyte%ORA11GR2> with rec(a,b,lvl,l, flg) as
2 (
3 select a, replace(b,' ',''), 1, length(replace(b,' ','')),
4 instr(a,substr(b,1),1)
5 from t
6 union all
7 select a, b, lvl+1, l, instr(a,substr(b,1,lvl+1),1)
8 from rec
9 where instr(a,substr(b,lvl+1),1)>0 and lvl+1<l
10 )
11 select *
12 from
13 (
14 select a, b, rank()over(partition by a order by lvl desc) as rnk
15 from
16 (
17 select *
18 from rec
19 )x
20 )x
21 where rnk=1
22 /
A B RNK
------------------------- ------------------------- ----------
abc-doej-123 doejane 1
abc-doej-123 doemary 1
xyz-smithp smithjohn 1
xyz-smithp smithpaul 1
the recursive one did not seem to work - no clue what "left" was supposed to be - and substr doesn't cut it.
I don't follow the logic. The first "recurse" would give us:
ops$tkyte%ORA11GR2> select a, replace(b,' ','') b, 1 lvl, length(replace(b,' ','')) l, instr(a,substr(b,1),1) flg
2 from t
3 /
A B LVL L FLG
------------------------- ------------------------- ---------- ---------- ----------
abc-doej-123 doejane 1 7 0
abc-doej-123 doemary 1 7 0
xyz-smithp smithjohn 1 9 0
xyz-smithp smithpaul 1 9 0
and the "second" recurse would give us:
ops$tkyte%ORA11GR2> select a, b, lvl+1, l, instr(a,substr(b,1,lvl+1),1)
2 from
3 (
4 select a, replace(b,' ','') b, 1 lvl, length(replace(b,' ','')) l, instr(a,substr(b,1),1) flg
5 from t
6 ) rec
7 where instr(a,substr(b,lvl+1),1)>0 and lvl+1<l
8 /
no rows selected
so we get - nothing?