declare
cursor test_Cursor is
select etpcode,max(rptdate) from vRptComFlag where etpcode in (select orgcode from tOrgDrpDisp where chainjymode ='1') and hzflag='1' group by etpcode;
v_orgcode varchar2(10);
v_rptdate varchar2(10);
begin
open test_Cursor;
fetch test_Cursor into v_orgcode,v_rptdate;
while test_Cursor%found loop
update Cmp_test_drp_mf set kcost=(select sum(kccost) from vRptComHzDisSale where orgcode=v_orgcode and rptdate=v_rptdate and orgcode = Cmp_test_drp_mf.orgcode);
fetch test_Cursor into v_orgcode,v_rptdate;
end loop;
close test_Cursor;
end;
update Cmp_test_drp_mf set kcost=(select sum(kccost) from vRptComHzDisSale where orgcode=v_orgcode and rptdate=v_rptdate and orgcode = Cmp_test_drp_mf.orgcode) where exists(select 1 from vRptComHzDisSale where orgcode=v_orgcode and rptdate=v_rptdate and orgcode = Cmp_test_drp_mf.orgcode)
;