網路城邦
上一篇 回創作列表 下一篇   字體:
用Select找出一批資料後, 再按資料的每一筆進行更新作業
2017/05/15 09:29:09瀏覽315|回應0|推薦0

declare cursor cur is (select tc_pqf33,tc_pqf07, xx.tc_pqh01 as tc_pqh01 , xx.tc_pqh03 as tc_pqh03 ,  xx.max_tc_pqh06b as max_tc_pqh06b

from dg.tc_pqf_file pqf ,

  (select tc_pqh01,tc_pqh03, max(tc_pqh06b) as max_tc_pqh06b from dg.tc_pqh_file pgh, dg.tc_pqg_file pqg

    where pgh.tc_pqh01 = pqg.tc_pqg01

      and pqg.tc_pqgconf = 'Y'

    group by tc_pqh01, tc_pqh03

    order by tc_pqh01, tc_pqh03) xx    /*end of select tc_pqh01,tc_pqh03....*/

where pqf.tc_pqf01 = xx.tc_pqh01

  and pqf.tc_pqf02 = xx.tc_pqh03

  and tc_pqf33 < xx.max_tc_pqh06b

  );  /*end of declare cursor*/

begin   /*再依 curcor cur 資料的每一筆進行更新作業*/

  for rec in cur loop

     update dg.tc_pqf_file set tc_pqf33 = rec.max_tc_pqh06b 

       where tc_pqf01 =  rec.tc_pqh01 and tc_pqf02 = rec.tc_pqh03;

  end loop;

end;     /*end of  再依 curcor cur 資料的每一筆進行更新作業*/
( 知識學習其他 )
回應 推薦文章 列印 加入我的文摘
上一篇 回創作列表 下一篇

引用
引用網址:https://classic-blog.udn.com/article/trackback.jsp?uid=shfm1969&aid=102683548