Oracle
 SQL >> Database >  >> RDS >> Oracle

Query Oracle lenta con REGEXP_SUBSTR(AGGREGATOR,'[^;]+',1,LEVEL)

A volte una tabella pipelined è più veloce: provate così:

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; 

Qui trovate una demo su sqlfiddle

E qui un'altra demo con 22 righe che contengono 3 valori ciascuna in aggregator: confrontate la prima e la seconda query per vedere la differenza.

Il collo di bottiglia tipico è la combinazione connect by level + regexp_substr, che viene rivalutata riga per riga: la funzione pipelined fa il lavoro in un solo passaggio.