Oracle Temporary Tables β³ΒΆ
Prerequisites: Table Management
Mentor's Note: Sometimes you need a "Scratchpad". You want to store data for a few minutes while you do a complex calculation, but you don't want that data to stay in the database forever. That's a Temporary Table. π‘
π The Scenario: The Rough Work πΒΆ
Imagine a student taking an exam. - Main Table: The Final Answer Sheet. - Temp Table: The Rough Sheet where you do your rough calculations. Once you finish the exam, the rough sheet is shredded.
π» 1. Global Temporary Tables (GTT)ΒΆ
The structure is permanent, but the data is temporary.
-ON COMMIT PRESERVE ROWS: Data stays until your session ends (logout).
- ON COMMIT DELETE ROWS: Data is wiped as soon as you hit COMMIT.
π» 2. Private Temporary Tables (Oracle 18c+)ΒΆ
Both the structure AND the data are temporary. They start with the prefix ORA$PTT_.
ποΈ Architect's Note: Undo & Redo π‘οΈΒΆ
Traditional tables generate a lot of "Undo" and "Redo" logs (to allow rollbacks). - The Architect's Secret: GTTs generate much less redo log entries. This makes them significantly faster for bulk operations. - Tip: Use temp tables to break down massive, slow queries into smaller, manageable steps.