【发布时间】:2019-02-03 06:04:42
【问题描述】:
declare
begin
for i in (select aid ,address from address)
loop
for j in (select aid ,address from address )
loop
if i.address=j.address then
if i.aid!=j.aid then
update employee_add
set aid=i.aid
where aid=j.aid;
delete from address
where aid=i.aid;
end if;
end if;
end loop;
end loop;
end;
/
此代码可以作为for loop 正常工作。之后它显示错误:------
*原因:外键值没有匹配的主键值。
*操作:删除外键或添加匹配的主键。
我有表employee[eid (primary key) ,ename],address[aid (primary
key),address],以及多对多关系表employee_add[eid,aid]。
请帮忙!提前致谢:)
【问题讨论】:
-
用通俗易懂的语言描述你要解决的问题。
-
实际上我有 3 个表地址、员工和雇员地址表,其中地址表有地址 id 和地址名称,地址 id 是主键,地址是重复地址,如 101-banglore 102-banglore 103-banglore 104 -pune 105-pune 106-hyderbad 和employee_address 有开斋节和援助,例如1-101,1-102,1-103,2-101,2-101,2-104,3-102,3-103... . 我想从具有相同地址的地址中删除重复数据,同时我想删除与employee_address 关联的地址,这样employee_address 表中不应该有任何数据丢失
标签: oracle plsql plsql-package