我正在使用查询来获取不同的行而不是分号分隔的值。
该表如下所示:
row_id aggregator
1 12;45
2 25
使用查询我希望输出看起来像:row_id aggregator
1 12
1 45
2 25
我正在使用以下查询:SELECT
DISTINCT ROW_ID,
REGEXP_SUBSTR(AGGREGATOR,'[^;]+',1,LEVEL) as AGGREGATOR
FROM DUMMY_1
CONNECT BY REGEXP_SUBSTR(AGGREGATOR,'[^;]+',1,LEVEL) IS NOT NULL;
即使对于 300 条记录,它也很慢,而且我必须处理 40000 条记录。
最佳答案
有时流水线表可以更快,试试这个:
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;
Here is a sqlfiddle demo
And here is another demo有 22 行,每行在聚合器中包含 3 个 val - 查看第一个和第二个查询之间的区别..
关于sql - oracle 使用 REGEXP_SUBSTR(AGGREGATOR ,'[^;]+' ,1,LEVEL) 查询速度很慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15106247/