oracle-databaseinsertmulti-table

Each When condition is tested for each row returned by the subquery?


So I set the autotrace on
ramin.tb001 had 10 rows.

enter image description here

enter image description here

In 1 version I use equality and in second less than
I want to know is the When condions reads 10 rows from ramin.tb001 and check condition or how?


Solution

  • I want to know is the When condions reads 10 rows from ramin.tb001 and check condition or how?

    Your first insert statement applies the condition when id = 6 and the second applies the condition when id < 10. In both cases the query reads the whole table and filters the result set by evaluating each row. How else could the query be processed?

    Well, if there were a unique index on ramin.tb001.id the optimiser would probably choose to use that instead. As only ID is selected in each case, the entire query can be satisfied from the index, which would be more efficient than scanning the table. This is true even if ramin.tb001 has just the one column, because ID would be sorted in the index, but maybe not in the table. Although given that the source data has such a trivial amount of data the difference in actual performance would be negligible.