The WITH clause (subquery factoring) allows the optimizer to materialize the result set into a temporary structure when the same subquery block is referenced multiple times in a query (for example, RW1 used more than once).
This behavior is not guaranteed with inline subqueries, which are typically merged into the main query block and re-evaluated as part of the execution plan.
Because of this, as Connor mentioned,
a WITH clause may attempt to dump intermediate results into a temporary table. Such an operation would be impossible when the database is only mounted (and not open), since temporary segments cannot be created in that state.
demo@ORA26AI> create table stage as select * from all_objects ;
Table created.
demo@ORA26AI> set autotrace traceonly exp
demo@ORA26AI> with rw1 as ( select owner, object_type , max(created) max_created, sum(object_id) sum_object_id
2 from stage
3 group by owner, object_type )
4 , rw2 as ( select owner, max(sum_object_id) max_sum_object_id
5 from rw1
6 group by owner )
7 select *
8 from rw1, rw2
9 where rw1.owner = rw2.owner
10 /
Execution Plan
----------------------------------------------------------
Plan hash value: 3469050691
-----------------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
-----------------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 370 | 66600 | 469 (14)| 00:00:01 |
| 1 | TEMP TABLE TRANSFORMATION | | | | | |
| 2 | LOAD AS SELECT (CURSOR DURATION MEMORY)| SYS_TEMP_0FD9D6622_101C98F | | | | |
| 3 | HASH GROUP BY | | 370 | 10360 | 464 (14)| 00:00:01 |
| 4 | TABLE ACCESS FULL | STAGE | 65175 | 1782K| 423 (6)| 00:00:01 |
|* 5 | HASH JOIN | | 370 | 66600 | 6 (34)| 00:00:01 |
| 6 | VIEW | | 18 | 1422 | 3 (34)| 00:00:01 |
| 7 | HASH GROUP BY | | 18 | 324 | 3 (34)| 00:00:01 |
| 8 | VIEW | | 370 | 6660 | 2 (0)| 00:00:01 |
| 9 | TABLE ACCESS FULL | SYS_TEMP_0FD9D6622_101C98F | 370 | 10360 | 2 (0)| 00:00:01 |
| 10 | VIEW | | 370 | 37370 | 2 (0)| 00:00:01 |
| 11 | TABLE ACCESS FULL | SYS_TEMP_0FD9D6622_101C98F | 370 | 10360 | 2 (0)| 00:00:01 |
-----------------------------------------------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
5 - access("RW1"."OWNER"="RW2"."OWNER")
demo@ORA26AI> select *
2 from ( select owner, object_type , max(created) max_created, sum(object_id) sum_object_id
3 from stage
4 group by owner, object_type ) rw1
5 , ( select owner, max(sum_object_id) max_sum_object_id
6 from ( select owner, object_type , max(created) max_created
7 , sum(object_id) sum_object_id
8 from stage
9 group by owner, object_type )
10 group by owner ) rw2
11 where rw1.owner = rw2.owner;
Execution Plan
----------------------------------------------------------
Plan hash value: 2175861137
--------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 370 | 66600 | 928 (14)| 00:00:01 |
|* 1 | HASH JOIN | | 370 | 66600 | 928 (14)| 00:00:01 |
| 2 | VIEW | | 18 | 1422 | 464 (14)| 00:00:01 |
| 3 | HASH GROUP BY | | 18 | 324 | 464 (14)| 00:00:01 |
| 4 | VIEW | | 370 | 6660 | 464 (14)| 00:00:01 |
| 5 | HASH GROUP BY | | 370 | 10360 | 464 (14)| 00:00:01 |
| 6 | TABLE ACCESS FULL| STAGE | 65175 | 1782K| 423 (6)| 00:00:01 |
| 7 | VIEW | | 370 | 37370 | 464 (14)| 00:00:01 |
| 8 | HASH GROUP BY | | 370 | 10360 | 464 (14)| 00:00:01 |
| 9 | TABLE ACCESS FULL | STAGE | 65175 | 1782K| 423 (6)| 00:00:01 |
--------------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
1 - access("RW1"."OWNER"="RW2"."OWNER")