Oracle two temporary tables created and used in detail

Source: Internet
Author: User

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.


Classification:
1. Session-Level staging table

A session-level temporary table is the data in a staging table that exists only during the session lifecycle, and when the user exits the end of the session, Oracle automatically clears the data from the staging table.

Format:

Create Global Temporary Table table_name
(
Col1 Type1,
Col2 Type2
...
)
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
(
Col1 Type1,
Col2 Type2
...
)
On Commit Delete Rows;

When a transaction ends (commit or rollback), Oracle automatically clears the data from the staging table.


The following shows the creation and use of temporary tables in Oracle 10g:


1. Create a transaction-level staging table, insert a piece of data, and query:

Create global temporary table TRANSACTION_TEMP_TB (col1 varchar) on commit delete Rows;insert into  transaction_te MP_TB values (' Test '); select * from  TRANSACTION_TEMP_TB;

2. When a commit or rollback operation is performed, the data in the temporary table is emptied, but the table structure still exists:


3. Create a session-level staging table, insert a piece of data, and query:

Create global temporary table SESSION_TEMP_TB (col1 varchar) on commit preserve rows;insert into SESSION_TEMP_TB value S (' Test '); select * from SESSION_TEMP_TB;


4. Perform a commit or rollback operation, the data in the table still exists, create a new command window (equivalent to open a new session), the data in the table can not be queried:


5. If the session that created the session temp table does not end, you cannot delete the temporary table because the temporary table is still in use, but the end session (which closes the command window that created the session-level temporary table) can be deleted:





Oracle two temporary tables created and used in detail

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.