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 資料的每一筆進行更新作業*/