declare
cursor cur1 is select * from address where aid in
(select Min(aid) from address group by
country,state,city,street_name,locality,house_no);
cursor cur2 is select * from address;
cur1_aid address.aid%type;
cur1_country address.country%type;
cur1_city address.city%type;
cur1_state address.state%type;
cur1_streetAddress address.street_name%type;
cur1_locality address.locality%type;
cur1_houseNo address.house_no%type;
cur2_aid address.aid%type;
cur2_country address.country%type;
cur2_city address.city%type;
cur2_state address.state%type;
cur2_streetAddress address.street_name%type;
cur2_locality address.locality%type;
cur2_houseNo address.house_no%type;
begin
open cur1;
loop
fetch cur1 into cur1_aid,cur1_country,cur1_state,cur1_city,cur1_streetAddress,cur1_locality,cur1_houseNo;
exit when cur1%NOTFOUND;
open cur2;
loop
fetch cur2 into cur2_aid,cur2_country,cur2_state,cur2_city,cur2_streetAddress,cur2_locality,cur2_houseNo;
exit when cur2%NOTFOUND;
if(cur1_country=cur2_country) and (cur1_state=cur2_state) and (cur1_city=cur2_city) and (cur1_streetAddress=cur2_streetAddress) and (cur1_locality=cur2_locality) and (cur1_houseNo=cur2_houseNo) then
if (cur1_aid!=cur2_aid) then
update employee_add set aid=cur1_aid where aid=cur2_aid;
delete address where aid=cur2_aid;
end if;
end if;
end loop;
close cur2;
end loop;
close cur1;
DELETE FROM employee_add a
WHERE ROWID > (SELECT MIN(ROWID) FROM employee_add b
WHERE b.eid=a.eid and b.aid=a.aid
);
end;
/
У меня есть три таблицы Employee (eid, ename), Адрес (помощь, страна, штат, город, уличный адрес, населенный пункт, houseNo) и таблица отношений (M2M) MANY TO MANY TABLE employee_add (eid, aid),
Я хочу удалить дубликаты из таблицы адресов и таблицы employee_add без потери данных