我编写了一个查询,其中我选择2列,这些列大约有40条记录。
现在我想通过一一选择来对这些记录进行求和计算。
在存储过程中,我使用了一个游标,其中m存储了这40条记录。并使用for循环对这些记录进行求和(一一计算)
但是对于第一条记录,sum变为空,并且我的循环没有从游标中获取另一条记录。
这就是为什么我无法逐个计算每条记录的总和的原因,因为我的for循环不再运行。
cursor details is
select distinct lpn_id v_olpn_id, lpn_detail_id v_olpn_detail_id
from lpn_detail ld
where size_value > '0'
and lpn_id in
( select lpn_id from lpn
where lpn_facility_status > '15'
and lpn_facility_status < '90'
and inbound_outbound_indicator = 'O' )
and item_id in
( select item_id from item_cbo where catch_weight_item = '1' )
and not exists
( select 1 from lpn_catch_weight lwc
where lwc.lpn_detail_id = ld.lpn_detail_id );
begin
for detail in details
loop
select sum(ld.ref_num4*td.qty_pulld) into v_total_weight
from lpn_detail ld, lpn l, task_dtl td
where l.lpn_id = ld.lpn_id
and l.tc_lpn_id=td.cntr_nbr
and ld.item_id=td.item_id
and l.lpn_id in
( select lpn_id from lpn where tc_lpn_id in
( select cntr_nbr from task_dtl
where carton_nbr in
( select tc_lpn_id from lpn
where lpn_id=detail.v_olpn_id ) ) )
and ld.ref_num4 is not null
and td.invn_need_type = 60
group by ld.item_id;
end loop;
答案 0 :(得分:0)
这可能会帮助您解决问题。...
textbox1.Text = entries[0];
此块代码在oracle 11g中运行良好