放分中,关于频繁访问,速度很慢的问题。
关于频繁访问,速度很慢的问题
--基础表
create table e_base (tid number,--主键
trow number,--行
tcol varchar2(2),--列
tempid number,--模板id
tformula varchar2(1000) --公式
);
insert into e_base values(1,9,'A',101,'YS(103,A,9)');
insert into e_base values(2,8,'B',101,'YS(101,A,9)');
insert into e_base values(3,4,'D',102,'YS(105,E,12)+YS(103,C,9)');
--结果表
create table e_result(
pid number,--主键
trow number,--行
tcol varchar2(2),--列
tempid number,--模板id
evalue number --值
);
现状:
基础表中公式字段tformula存储的是用户定义的公式,需要到结果表中根据模板id(tempid)对对应解析。
select 解析函数(tformula),tempid from e_base where tempid=101;
问题:某一模板下公式少的时候,解析速度还可以,如果公式多了,如 4000条记录中,1200条存在公式,解析速度很慢,而且,e_result是最终结果表,数据量也很大。请大家帮忙,寻找个新思路。
附解析函数的思路:
根据固定标识符:逗号 提出,然后拼出sql
Loop
v_bindex := Instr(s_formula, 'YS(');
v_eindex := instr(s_formula, ')', v_bindex);
Exit When(Nvl(v_bindex, 0) = 0);
s_temp := Trim(Substr(s_formula,
v_bindex + 3,
v_eindex - v_bindex - 3));
t_tempid := substr(s_temp,1,instr(s_temp,',')-1);
t_col := substr(s_temp,instr(s_temp,',')+1,instr(s_temp,',',1,2)-instr(s_temp,',')-1);
t_row := substr(s_temp,instr(s_temp,',',1,2)+1,instr(s_temp,',',1,3)-instr(s_temp,',',1,2)-1);
s_sql := '(select nvl(evalue,0) from e_result where tempid=' || t_tempid ||' and trow='||t_row||
' and tcol='''||t_col||''')';
s_final := replace(s_final,'YS('||s_temp||')',s_sql);
s_formula := Substr(s_formula, v_eindex + 1);
End Loop;
s_final := 'select '||s_final||' from dual';
execute immediate s_final into s_final;
Return s_final;