新人求助!PLSQL游标问题
本帖最后由 murphy0410 于 2013-05-28 16:20:25 编辑 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;
Cmp_test_drp_mf 是一个我简历的临时表,
我UPDATE只有最后一行更新了数据,不知道为何,请大神们指教下,谢谢 PL/SQL
[解决办法]
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)
;
update如果不加WHERE条件都是UPDATE整个表的记录,所以你那个是最后一行满足了条件,其他行不满足,全部UPDATE成NULL了。