Temporary oracle table

Source: Internet
Author: User
Tags types of tables

An Oracle temporary table can have two types of temporary tables
1. Session-level temporary table
Saves the data used by the current session, which exists during the data session. After each submission, ORACLE truncates the table (deletes all rows). The data inserted by two different sessions is irrelevant.
2. Transaction-level temporary tables
Save the data used by the current transaction. The data only exists during the transaction. When the session is interrupted, ORACLE truncates the table. Session data is private to the current session. Each session can only view and modify its own data. The DML lock is not added to the data in the temporary table.
Ii. Create syntax
1 SESSION-level temporary table
SQL code
Create global temporary table temp_tbl (col_a varchar2 (30 ))
On commit preserve rows

2. TRANSACTION-level temporary table
SQL code
Create global temporary table temp_tbl (col_a varchar2 (30 ))
On commit delete rows

These two types of tables are inserted and queried in the same way as other tables.
Differences between the three types of temporary tables
Session-level temporary tables use on commit preserve rows, while transaction-level temporary tables use on commit delete rows. In usage, session-level data is truncated only when the session ends temporary tables, in addition, the data in the temporary transaction table is truncated, whether it is commit, rollback, or session termination.
4. Create
SQL code
Create procduce test
Is
Isql varchar2 (200 );
Dptable varchar2 (100): = 'drop table test ';
Begin
Isql: = 'Create global temporary table test (sid int, sname varchar2 (20) on commit delete rows;
Execute immediate isql; -- create a temporary table
Insert into test values (1, 'abc ');
Execute immediate dptable; --- delete a temporary table
End;

Author: "Getting to the ground"
 

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.