如何使用 oracle 在一个查询中删除多个 table 的记录

How to delete record for multiple table in one query using oracle

For Example I have execute this sql query which is given a result. I want to delete those result using oracle query.

 Select 
a.ENAME    ,
a.JOB,
a.MGR,
a.HIREDATE,
a.SAL,
b.DEPTNO,
b.DNAME,
b.LOC
from emp a , dept b where a.DEPTNO=b.DEPTNO and a.DEPTNO=10
DELETE FROM emp , dept 
WHERE a.DEPTNO=b.DEPTNO

没有任何命令可以从两个 table 中删除 link。但我提出两种情况。第一种情况可用于非 parent/child tables。第二种情况可用于 parent/child tables.

第一:收集你所有的公共PK或你table的任何公共领域。 (当然你有一个共同的领域)。像下面的查询:

(Select a.DEPTNO from emp a , dept b where a.DEPTNO=b.DEPTNO and a.DEPTNO=10)

然后在一个事务中使用一系列删除命令。

delete from dept where DEPTNO IN (Select a.DEPTNO from emp a , dept b where a.DEPTNO=b.DEPTNO and a.DEPTNO=10)
delete from emp where DEPTNO IN (Select a.DEPTNO from emp a , dept b where a.DEPTNO=b.DEPTNO and a.DEPTNO=10)

其次:使用CASCADE DELETE配置。 (仅适用于 parent/child tables)
如果无法控制副作用,此解决方案是有害的。
在级联删除中,父table中的一条记录被删除后,子table中对应的记录也会自动删除。