Hi all,
I have to find the people who have same last name,birth_date and org_id with different peo_id.After finding,i have to update the other tables.if the last name has more than 1 peo_id then i have to take minimum peo_id and update the other peo_id's to that min peo_id.i have written a procedure.but it's not giving the correct result.Can any one please help.I need it very urgent.
CREATE OR REPLACE PROCEDURE Merge_delete_Duplicate_Clients AS
pv_good_peo_id NUMBER;
--pv_bad_peo_id NUMBER ;
CURSOR peo_merge is
SELECT psr.peo_id, psr.FIRST_NAME, psr.LAST_NAME,psr.BIRTH_DATE, psr.OWNER_ORG_ID
FROM PROV_SERVICE_RECIPIENT@eispenet psr
WHERE psr.FIRST_NAME||psr.LAST_NAME||psr.BIRTH_DATE||psr.OWNER_ORG_ID IN (
SELECT psr.FIRST_NAME||psr.LAST_NAME||psr.BIRTH_DATE||psr.OWNER_ORG_ID
FROM PROV_SERVICE_RECIPIENT@eispenet psr
GROUP BY psr.FIRST_NAME, psr.LAST_NAME,psr.BIRTH_DATE, psr.OWNER_ORG_ID
HAVING COUNT(*) > 1)
ORDER BY psr.OWNER_ORG_ID,psr.LAST_NAME,psr.FIRST_NAME;
BEGIN
for i in peo_merge loop
select min(peo_id)
into pv_good_peo_id
from PROV_SERVICE_RECIPIENT@eispenet psr
where last_name = i.last_name
and birth_date = i.birth_date
and owner_org_id = i.owner_org_id;
if i.peo_id != pv_good_peo_id then
UPDATE eisprov.ADDRESS SET PEO_ID = pv_good_peo_id WHERE peo_id = i.peo_id;
UPDATE eisprov.ADDRESS SET created_by = pv_good_peo_id WHERE created_by = i.peo_id;
UPDATE eisprov.ADDRESS SET modified_by = pv_good_peo_id WHERE modified_by = i.peo_id;
UPDATE eisprov.DEPT_ASSESSMENT SET PEO_ID = pv_good_peo_id WHERE peo_id = i.peo_id;
UPDATE eisprov.DEPT_ASSESSMENT SET created_by = pv_good_peo_id WHERE created_by = i.peo_id;
UPDATE eisprov.DEPT_ASSESSMENT SET modified_by = pv_good_peo_id WHERE modified_by = i.peo_id;
UPDATE eisprov.PEOPLE_OTHER_ID SET PEO_ID = pv_good_peo_id WHERE peo_id = i.peo_id;
UPDATE eisprov.PEOPLE_OTHER_ID SET created_by = pv_good_peo_id WHERE created_by = i.peo_id;
UPDATE eisprov.PEOPLE_OTHER_ID SET modified_by = pv_good_peo_id WHERE modified_by = i.peo_id;
UPDATE eisprov.PEOPLE_RELATE SET PEO_ID = pv_good_peo_id WHERE peo_id = i.peo_id;
UPDATE eisprov.PEOPLE_RELATE SET RELATED_PEO_ID = pv_good_peo_id WHERE RELATED_PEO_ID = i.peo_id;
UPDATE eisprov.PEOPLE_RELATE SET created_by = pv_good_peo_id WHERE created_by = i.peo_id;
UPDATE eisprov.PEOPLE_RELATE SET modified_by = pv_good_peo_id WHERE modified_by = i.peo_id;
UPDATE eisprov.MHENROLLMENT_FORM_BATCH_NEW_V2 SET EIS_PEO_ID = pv_good_peo_id WHERE EIS_peo_id = i.peo_id;
UPDATE eisprov.MH_ISP_BATCH_FEED SET EIS_PEO_ID = pv_good_peo_id WHERE EIS_peo_id = i.peo_id;
DELETE FROM eisprov.PROV_SERVICE_RECIPIENT WHERE PEO_ID = i.peo_id;
end if;
end loop;
COMMIT;
END;
/
Thanks,
Latha
I have to find the people who have same last name,birth_date and org_id with different peo_id.After finding,i have to update the other tables.if the last name has more than 1 peo_id then i have to take minimum peo_id and update the other peo_id's to that min peo_id.i have written a procedure.but it's not giving the correct result.Can any one please help.I need it very urgent.
CREATE OR REPLACE PROCEDURE Merge_delete_Duplicate_Clients AS
pv_good_peo_id NUMBER;
--pv_bad_peo_id NUMBER ;
CURSOR peo_merge is
SELECT psr.peo_id, psr.FIRST_NAME, psr.LAST_NAME,psr.BIRTH_DATE, psr.OWNER_ORG_ID
FROM PROV_SERVICE_RECIPIENT@eispenet psr
WHERE psr.FIRST_NAME||psr.LAST_NAME||psr.BIRTH_DATE||psr.OWNER_ORG_ID IN (
SELECT psr.FIRST_NAME||psr.LAST_NAME||psr.BIRTH_DATE||psr.OWNER_ORG_ID
FROM PROV_SERVICE_RECIPIENT@eispenet psr
GROUP BY psr.FIRST_NAME, psr.LAST_NAME,psr.BIRTH_DATE, psr.OWNER_ORG_ID
HAVING COUNT(*) > 1)
ORDER BY psr.OWNER_ORG_ID,psr.LAST_NAME,psr.FIRST_NAME;
BEGIN
for i in peo_merge loop
select min(peo_id)
into pv_good_peo_id
from PROV_SERVICE_RECIPIENT@eispenet psr
where last_name = i.last_name
and birth_date = i.birth_date
and owner_org_id = i.owner_org_id;
if i.peo_id != pv_good_peo_id then
UPDATE eisprov.ADDRESS SET PEO_ID = pv_good_peo_id WHERE peo_id = i.peo_id;
UPDATE eisprov.ADDRESS SET created_by = pv_good_peo_id WHERE created_by = i.peo_id;
UPDATE eisprov.ADDRESS SET modified_by = pv_good_peo_id WHERE modified_by = i.peo_id;
UPDATE eisprov.DEPT_ASSESSMENT SET PEO_ID = pv_good_peo_id WHERE peo_id = i.peo_id;
UPDATE eisprov.DEPT_ASSESSMENT SET created_by = pv_good_peo_id WHERE created_by = i.peo_id;
UPDATE eisprov.DEPT_ASSESSMENT SET modified_by = pv_good_peo_id WHERE modified_by = i.peo_id;
UPDATE eisprov.PEOPLE_OTHER_ID SET PEO_ID = pv_good_peo_id WHERE peo_id = i.peo_id;
UPDATE eisprov.PEOPLE_OTHER_ID SET created_by = pv_good_peo_id WHERE created_by = i.peo_id;
UPDATE eisprov.PEOPLE_OTHER_ID SET modified_by = pv_good_peo_id WHERE modified_by = i.peo_id;
UPDATE eisprov.PEOPLE_RELATE SET PEO_ID = pv_good_peo_id WHERE peo_id = i.peo_id;
UPDATE eisprov.PEOPLE_RELATE SET RELATED_PEO_ID = pv_good_peo_id WHERE RELATED_PEO_ID = i.peo_id;
UPDATE eisprov.PEOPLE_RELATE SET created_by = pv_good_peo_id WHERE created_by = i.peo_id;
UPDATE eisprov.PEOPLE_RELATE SET modified_by = pv_good_peo_id WHERE modified_by = i.peo_id;
UPDATE eisprov.MHENROLLMENT_FORM_BATCH_NEW_V2 SET EIS_PEO_ID = pv_good_peo_id WHERE EIS_peo_id = i.peo_id;
UPDATE eisprov.MH_ISP_BATCH_FEED SET EIS_PEO_ID = pv_good_peo_id WHERE EIS_peo_id = i.peo_id;
DELETE FROM eisprov.PROV_SERVICE_RECIPIENT WHERE PEO_ID = i.peo_id;
end if;
end loop;
COMMIT;
END;
/
Thanks,
Latha