|
|
create view tt0 as
select 1 id, 2 amount from dual union all
select 2 , 2 amount from dual union all
select 3 , 3 amount from dual union all
select 4 , 5 amount from dual union all
select 5 , 2 amount from dual union all
select 6 , 8 amount from dual union all
select 7 , 1 amount from dual union all
select 8 , 2 amount from dual union all
select 9 , 3 amount from dual union all
select 10 , 3 amount from dual
;
create view tt1 as
select * from tt0
;
create view ttall as
select * from tt0
;
declare
n number := 1;
m number := 0;
x_amount number:=700;--------需要计算的值
begin
while (m = 0) loop
execute immediate ('create or replace view ttall as
select tts.id ||''-''|| tt0.id id ,tts.amount+ tt0.amount amount
from
(select min(id ) id ,amount
from tt' || n || '
group by amount ) tts,tt0
where tts.amount<'|| x_amount);
execute immediate ('create or replace view tt' || to_char(n + 1) ||
' as
select tts.id ||''-''|| tt0.id id ,tts.amount+ tt0.amount amount
from
(select min(id ) id ,amount
from
tt' || n || '
group by amount ) tts,tt0
where tts.amount<'|| x_amount);
n := n + 1;
select count(1) into m from ttall where amount = x_amount;
end loop;
for cur in (select id from ttall where amount = x_amount) loop
dbms_output.put_line(cur.id);
end loop;
end;
[ 本帖最后由 grubbyoo 于 2009-9-5 09:18 编辑 ] |
|