create procedure pro
as
begin
update dm_wz_his a set f_zc_day03=(select f_sl from (select * from his where f_wzyy is not null order by f_rq desc) b where a.f_cdxs=b.f_cdxs and rownum<4);
end;
/

解决方案 »

  1.   

    declare cursor pc_cur is 
          select count(b.f_sl) as f_pc,b.f_cdxs
             from (select * from his where f_wzyy is not null order by f_rq desc) b,his
                where b.f_cdxs=his.f_cdxs and rownum<=10
          group by b.f_cdxs;
          pc_rec pc_cur% rowtype;
       begin
          for pc_rec in pc_cur loop
             update dm_wz_his set f_wz_pc10=pc_rec.f_pc
                where dm_wz_his.f_cdxs=pc_rec.f_cdxs and rownum<=10;
          end loop;
       end;
    但是这样写的话有错误:它相当于count(*)了没有起到rownum的作用啊!
      

  2.   


    _WZ_PC10
    --------
          12
         110
          38
           3
         282
           1
           1
           1
           1
           2
           2_WZ_PC10
    --------
           1
           1
           5
           5
          22
           2
           5
           1
           7
           1
           4_WZ_PC10
    --------
           3
           1
           2
           5
           2
          20
           3
         275
           1
           5
          33
      

  3.   

    这里的结果都大于10了!你在这里rownum的只是一张有所有f_cdxs的表!但是它要求的是每个f_cdxs的rownum的前十个!所以这样做我现在还不会!!^_^!