create or replace procedure p_pds is
v_pds_name DCS_PDS_MATCH_BASE.PDS_NAME %type; /*游标into值*/
counter number(2); /*牌号种类数*/
start_counter number(2) := 1;
pds_counter number(2); /*每种牌号一共有多少条数据*/
cursor pds is select distinct(t.pds_name) from DCS_PDS_MATCH_BASE t;
begin
open pds;
select count(distinct(d.pds_name)) into counter from DCS_PDS_MATCH_BASE d; /*不同的牌号种类数有多少*/
for start_counter in 1..counter loop
fetch pds into v_pds_name;
select count(p.pds_name) into pds_counter from DCS_PDS_MATCH_BASE p where p.pds_name = v_pds_name
and p.end_date = to_date('2099-12-30','yyyy-mm-dd');/*每种牌号一共有多少条数据*/
if pds_counter >=2 then
update DCS_PDS_MATCH_BASE set DCS_PDS_MATCH_BASE.end_date = (select p.start_date from DCS_PDS_MATCH_BASE p
where p.f_id=(select max(p.f_id) from DCS_PDS_MATCH_BASE p))
where DCS_PDS_MATCH_BASE.f_id = ( select min(p.f_id) from DCS_PDS_MATCH_BASE p
where p.pds_name = (select p.pds_name from DCS_PDS_MATCH_BASE p
where p.f_id= (select max(p.f_id) from DCS_PDS_MATCH_BASE p))
and to_char(p.end_date,'yyyy-mm-dd')='2099-12-30');
COMMIT;
end if;