|
|
declare
type test_t is table of t_money%rowtype index by binary_integer;
res test_t;
l_row binary_integer:=1;
sums number;
cal varchar2(1000);
seq varchar2(1000);
begin
for via in (select * from t_money) loop
res(l_row):=via;
l_row:=l_row+1;
end loop;
--dbms_output.put_line(res.count);
for i in res.first .. 2**res.last loop -- <=> for i in 1..1024 loop
sums:=0;
seq:='';
cal:='';
for j in res.first .. res.count loop -- <=> select j in 1 .. 10 loop
if (bitand(i,2**j) <> 0) then
sums:=sums+res(j).amount;
cal:=cal||res(j).amount||'+';
seq:=seq||j||',';
end if;
end loop;
if (sums=10) then
cal:=substr(cal,1,length(cal)-1);
seq:=substr(seq,1,length(seq)-1);
dbms_output.put_line('结果是:'||cal||'='||sums);
dbms_output.put_line('序列是:'||seq);
exit;
end if;
end loop;
end;
有问题如下:
1、对上面两个循环能玖举所有的情况表示怀疑,好像没什么有力论据
2、if (bitand(i,2**j) <> 0) then判断条件的依据是什么?个人感觉应该是内层循环j值不等于外层循环的i即可。 |
|