Temporal tables in Oracle

Source: Internet
Author: User
Tags types of tables

Temporal tables in Oracle

In Oracle, a temporal table is "static", and it needs to be created one time, just like a normal data table, and its structure is valid from creation to deletion. In contrast to other types of tables, temporary tables allocate space only when the user actually adds data to the table, and the allocated space comes from the temporary table space. This avoids the contention for storage space with the persistent object's data.

The syntax for creating a temporary table is as follows:

CREATE GLOBAL TEMPORARY TABLE table_name(    column_name data_type,[column_name data_type,...])ON COMMIT DELETE|PRESERVE ROWS;

Because the data stored by the staging table is valid only during the current transaction or session
Therefore, temporary tables are divided into transaction-level temporary tables and session-level temporary tables.

transaction-level staging table

To create a transaction-level temporary table, you need to use the on COMMIT delete rows clause, and the records for the transaction-level staging table are automatically deleted after each commit transaction.

Example 1:

CREATE GLOBAL TEMPORARY TABLE tbl_user_transcation(       ID NUMBER,       uname VARCHAR2(10),       usex VARCHAR2(2),       ubirthday DATE)ON COMMIT DELETE ROWS;
session-level staging table

To create a session-level temporary table, you need to use the on COMMIT PRESERVE rows clause, and the record of the session-level staging table is automatically deleted after the user disconnects from the server.

Example 2:

CREATE GLOBAL TEMPORARY TABLE tbl_user_session(       ID NUMBER,       uname VARCHAR2(10),       usex VARCHAR2(2),       ubirthday DATE)ON COMMIT PRESERVE ROWS;
Operation Temp Table

Temporal tables in Oracle

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.