Suponiendo que su tabla se llame temp
(probablemente no, cámbielo por el nombre correcto de su tabla)
Usé una subconsulta para encontrar todas las palabras en tu tabla:
select distinct regexp_substr(t.name, '[^ ]+',1,level) word , t.name, t.id
from temp t
connect by level <= regexp_count(t.name, ' ') + 1
esta consulta divide todas las palabras de todos los registros. Le puse un alias words
.
Luego lo uní con su tabla (en la consulta se llama temp) y conté el número de ocurrencias en cada registro.
select words.word, count(regexp_count(tt.name, words.word))
from(
select distinct regexp_substr(t.name, '[^ ]+',1,level) word , t.name, t.id
from temp t
connect by level <= regexp_count(t.name, ' ') + 1) words, temp tt
where words.id= tt.id
group by words.word
También puede agregar:
having count(regexp_count(tt.name, words.word)) > 1
actualizar :para un mejor rendimiento, podemos reemplazar la subconsulta interna con los resultados de una función canalizada:
primero, cree un tipo de esquema y una tabla del mismo:
create or replace type t is object(word varchar2(100), pk number);
/
create or replace type t_tab as table of t;
/
luego crea la función:
create or replace function split_string(del in varchar2) return t_tab
pipelined is
word varchar2(4000);
str_t varchar2(4000) ;
v_del_i number;
iid number;
cursor c is
select * from temp; -- change to your table
begin
for r in c loop
str_t := r.name;
iid := r.id;
while str_t is not null loop
v_del_i := instr(str_t, del, 1, 1);
if v_del_i = 0 then
word := str_t;
str_t := '';
else
word := substr(str_t, 1, v_del_i - 1);
str_t := substr(str_t, v_del_i + 1);
end if;
pipe row(t(word, iid));
end loop;
end loop;
return;
end split_string;
ahora la consulta debería verse así:
select words.word, count(regexp_count(tt.name, words.word))
from(
select word, pk as id from table(split_string(' '))) words, temp tt
where words.id= tt.id
group by words.word