sql >> Base de Datos >  >> RDS >> Oracle

la consulta de Oracle es lenta con REGEXP_SUBSTR(AGGREGATOR,'[^;]+',1,LEVEL)

A veces, una tabla canalizada puede ser más rápida, intente esto:

create or replace type t is object(word varchar2(100), pk number);
/
create or replace type t_tab as table of t;
/

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 DUMMY_1; 

begin

  for r in c loop
    str_t := r.aggregator;
    iid   := r.row_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;

Aquí hay una demostración de sqlfiddle

Y aquí hay otra demostración con 22 filas que contienen 3 valores en el agregador cada una:vea la diferencia entre la primera y la segunda consulta.