In addition to saving permanent tables, the Oracle database can also establish temporary table temporary tables. These temporary tables are used to hold data for session sessions, or to store data in a transaction. When the session exits or the user submits a commit and rolls back the rollback transaction, the data for the temporary table is automatically emptied, but the structure of the temporary table and the metadata are also stored in the user's data dictionary.
1. Session-Level staging table
A session-level temporary table is the data in a staging table that exists only during the session life cycle, and when the session ends, Oracle automatically clears the data from the staging table. So here is a common knowledge point, that is, the data of the respective session can only be seen by themselves, different sessions to see the data of their own (different data), this knowledge point in the optimization scenario using a lot.
Format:
Create Global Temporary Table table_name
(xxx int) On Commit Preserve Rows;
2. Transaction-level staging table
A transaction-level temporary table refers to the data in a staging table that exists only during the transaction life cycle.
Create Global Temporary Table table_name
(xxx int)
On Commit Delete Rows;
When a transaction ends (commit or rollback), Oracle automatically clears the data from the staging table. Data for the same transaction-level staging table is also independent between sessions
The most common scenarios for business optimization are as follows:
1 Users bulk scour data storage at a specific time
2 database background through a transit table (XXX) first to the user data landing
3 According to various logic, the XXX table data insert into various business tables
Question 1: A lot of developers put XXX into a regular table, and the developer idea that this is actually just a transit temporary table, the design of the index naturally many people also ignored.
Question 2: This XXX through the multi-user brush data comes in, the amount of data involved should be very large, if designed as a normal table, it is certainly appropriate to some of the processed data to delete, which significantly affect business efficiency.
The performance of this business can be boosted by the nature of the temporal table.
Oracle Temp Table