Delete with subquery without WHERE or IN (Key-Preserved-Table)

Here is the delete clause, it works fine for me, but I wonder how the oracle knows which table deletes the data?

delete from (select * from t1 join t2  
on t1.field1 = t2.field1) 

What is the mechanism for determining which table will be deleted?

In my case, the data was deleted from t1, the ratio between t1 and t2 is n → 1.

If I change the return order of subselect, the result will be the same:

delete from (select * from t2 join t1  
on t1.field1 = t2.field1) 
+4
source share
1 answer

Oracle will only delete from the so-called stored key table . This is a table whose key is saved as a result of the join. In other words, rows of a saved key table can appear only once as a result of a join.

- n -> 1 t1 t2. , Oracle t1 , t2.


. . OP :

create table a (n int primary key);
create table b (n int);

insert into a values(1);
insert into b values(1);
insert into b values(1);

b:

delete from (select * from a join b on a.n = b.n);

b? Oracle b row . , b - , . :

select a.*, a.rowid, b.*, b.rowid from a join b on a.n = b.n;

  a.n | a.ROWID            | b.n| b.ROWID
  ----+--------------------+----+-------------------
    1 | AAAKUKAAEAAAAv8AAA |  1 | AAAKUMAAEAAAAwMAAA 
    1 | AAAKUKAAEAAAAv8AAA |  1 | AAAKUMAAEAAAAwMAAB 
+3

All Articles