Oracle temporary table creation syntax and usage skills

Source: Internet
Author: User
OracleTemporaryTables (Oracle temporary table) 1. Create A temporary table syntax. A. ONCOMMITDELETEROWS defines the CREATEGLOBALTEMPORAR method for creating A transaction-level temporary table.

Oracle Temporary Tables (Oracle Temporary table) 1. create a Temporary table syntax A. on commit delete rows defines the method for creating A transaction-level Temporary table CREATE GLOBAL TEMPORAR

Oracle Temporary Tables (Temporary Oracle table)

1. Create a temporary table syntax

A. on commit delete rows defines how to create A transaction-level temporary table

Create global temporary table TABLE_NAME

----- (COUMNS ...)

----- As select... From table...

On commit delete rows;

When the current session issues the commit/rollback command, all data in the transaction cycle is automatically deleted by Oracle (Oracle truncate table ). But it does not affect the data of any other sessions.

B. ON COMMIT PRESERVE ROWS defines how to create a session-level temporary table

Create global temporary table TABLE_NAME

----- (COUMNS ...)

----- As select... From table...

On commit preserve rows;

The current session ends (the user Exits normally/the user does not exit normally/the Oracle instance crashes). Oracle deletes the data in this session (Oracle truncate table ). But it does not affect the data of any other sessions.

2. Features

A. After temporary table data is cleared automatically, the structure and metadata of the temporary table are stored in the user's data dictionary. Table definitions are visible to all sessions

B. DML locks are not required for temporary tables.

C. You can index temporary tables and create views based on temporary tables.

D. The index on the temporary table is also temporary and only valid for the current session or transaction.

E. Temporary tables can have triggers

F. You can use the export and import tools to import and export definitions of temporary tables, but cannot export data.

3. Tips

A. When an SQL statement is associated with two or more tables, it is associated with some small tables. You can split a large table and store a small result set in a temporary table.

B. Some temporary data may need to be stored during program execution. It is very convenient to put such data in the temporary table.

C. Use temporary tables in the stored procedure:

1> before creating a temporary table, add the table name judgment.

Select count (*) into v_count from user_tables where table_name = 'xxx ';

If v_count = 0 then

Create global temporary table...

At the end of the stored procedure, remember to delete the table.

Execute immediate 'drop table t_temp ';

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.