Global Temporary Tables (GTT) are specialized database objects designed to store temporary data that is automatically managed by Oracle.
Unlike regular tables, GTT definitions are permanent and visible to all sessions, but the data within them is private to each session or transaction.
Temporary tables are a tool that can be very important for solving performance issues in some very complex queries.
Also, these tables can be used to store temporary results from queries that are executed multiple times within code.
Many Oracle DBAs believe that temporary tables are unnecessary and that the Oracle optimizer can efficiently handle all queries, and that solving performance issues is the responsibility of SQL developers (who must write efficient SQL) and DBAs (who must design and manage the database's logical and physical structure—indexes, datafiles, etc.).
While that is partly true, it does not eliminate the fact that in practice there are always exceptions.
In fact, Oracle created temporary tables because there are certainly cases where they can be useful! Personally, I believe it's the responsibility of SQL developers and DBAs to discuss the various possible solutions (including temporary tables) and weigh the time and effort required to implement each solution against the expected performance gains.
Oracle allows the creation of two types of temporary tables: transaction-level and session-level temporary tables.
Key Characteristics of GTT:
- Table structure is permanent and shared across all sessions.
- Data is private to each session or transaction.
- No logging to redo logs (faster DML operations).
- Automatic cleanup when session/transaction ends.
- Support for indexes, constraints, and triggers.
- Statistics are maintained separately for each session.