with t( lt, rt) as (
select 'Kiki Cola 50 ml bottle', 'Kiki Cola 50 ml bottle' from dual union all
select 'Kiki Cola 50 ml bottle', '50 ml Kiki Cola bottle' from dual union all
select 'Kiki Cola 50 ml bottle', 'Kiki Cola 50 ml' from dual union all
select 'Kiki Cola 50 ml bottle', 'Kiki Cola Light bottle 50 ml' from dual union all
select 'Kiki Cola 50 ml bottle', 'Coca Cola 50 ml bottle' from dual ),
q as (select rownum rn, lt, rt,
'"'||replace(lt, ' ', '", "')||'"' ltx,
'"'||replace(rt, ' ', '", "')||'"' rtx from t )
select rn, lt, rt,
case when lt = rt then 'same'
when fl = 0 and fr = 0 then 'swapped'
when fl = 1 and fr = 0 then 'contains'
when fl = 0 and fr = 1 then 'contained in'
else 'not same'
end pattern
from (
select coalesce(l.rn, r.rn) rn,
max(case when l.rn is null then 1 else 0 end) fl,
max(case when r.rn is null then 1 else 0 end) fr
from (select rn, trim(column_value) lw from q, xmltable(ltx)) l
full join (select rn, trim(column_value) rw from q, xmltable(rtx)) r
on l.rn = r.rn and l.lw = r.rw
group by coalesce(l.rn, r.rn))
join q using (rn)
Результат:
RN LT RT PATTERN
------ ---------------------- ---------------------------- ------------
1 Kiki Cola 50 ml bottle Kiki Cola 50 ml bottle same
2 Kiki Cola 50 ml bottle 50 ml Kiki Cola bottle swapped
3 Kiki Cola 50 ml bottle Kiki Cola 50 ml contained in
4 Kiki Cola 50 ml bottle Kiki Cola Light bottle 50 ml contains
5 Kiki Cola 50 ml bottle Coca Cola 50 ml bottle not same
Разделить строку на слова (здесь xml -way, connect by
тоже работает или функционировать), выполнить сравнение, используя полное объединение, считать нули, группировать по и показать шаблон, используя case when
.