oracle sql公式拆分,请大神解答!
例如:
编号 公式
101 (a+b)/(c*d)
要求拆分,插入到表里。
编号 公式项
101 a
101 b
101 c
101 d 展开
declare
v_length number;
v_str varchar(20);
v_Temp varchar(20);
v_result varchar(20);
cursor cur_test is
select c from test1;
begin
open cur_test;
loop
fetch cur_test
into v_str;
exit when cur_test%notfound;
select length(c) into v_length from test1 where c = v_str;
v_Temp := v_str;
for inx in 1 .. v_length loop
select substrb(v_Temp, 1, 1)
into v_result
from test1
where c = v_str;
if v_result <> '(' and v_result <> ')' and v_result <> '+' and
v_result <> '-' and v_result <> '*' and v_result <> '/' then
dbms_output.put_line(v_result);
end if;
v_Temp := ltrim(v_Temp, v_result);
end loop;
end loop;
close cur_test;
end;
可以将公式分解,插入表的语句你自己在上面过程中做下吧。测试数据:
存储过程:
create or replace procedure chaifen(iv_num number, iv_str varchar2) is
li_char varchar2(4);
li_count number;
li_i number;
li_asc number;
begin
li_count := 0;
li_i := 1;
select length(iv_str) into li_count from dual;
loop
exit when li_i > li_count;
select substr(iv_str, li_i, 1) into li_char from dual;
select Ascii(li_char) into li_asc from dual;
if li_asc > 64 and li_asc < 123 then
insert into madw_tablename values (iv_num, li_char);
commit;
li_i := li_i + 1;
else
li_i := li_i + 1;
end if;
end loop;
exception
when others then
rollback;
return;
end chaifen;
-----
调用存储过程完成
begin
chaifen(101,’a+b+c‘);
end; ---------- 这里能插入表的公式项只能是A~Z,a~z