[Temporary table of Oracle database]

Temporary table: Like a normal table, it has a structure, but the management of data is different. The temporary table stores the intermediate result set of a transaction or session. The data saved in the temporary table is only visible to the current session, and all sessions cannot see other Session data, even if submitted by other sessions, cannot be seen. Temporary tables do not have concurrency because they are independent of the current session.

 

When creating a temporary table, Oracle only creates the structure of the table (defined in the data dictionary), and does not initialize the memory space. When a session uses a temporary table, ORALCE will allocate a memory space from the temporary table space of the current user. That is to say, storage space is allocated to the temporary table only when data is inserted into the temporary table.

 

 

ORACLE's temporary table plays a very important role in the application system. It allows users to only operate their own data without interfering with each other, without worrying about destroying or affecting other SESSION/TRANSACTION data, which is also a kind of data security. Solution. 

 

Temporary tables are divided into SESSION and TRANSACTION. SESSION-level temporary table data exists in the entire SESSION until the end of this SESSION; and TRANSACTION-level temporary table data disappears after the end of TRANACTION, that is, COMMIT/ROLLBACK or end SESSION will be cleared TRANSACTION temporary table data. 

 

The syntax of the two temporary tables: 

    create global temporary table 临时表名 on commit preserve|delete rows  

    When using preserve, it is a temporary table of SESSION level, and using delete is a temporary table of TRANSACTION level. 

 

 

Although the created temporary table exists, if you insert a record and then use another connection to board to select, the record is empty.   

--ON COMMIT DELETE ROWS indicates that the temporary table is specified by the transaction, and ORACLE will truncate the table (delete all rows) after each commit 

--ON COMMIT PRESERVE ROWS indicates that the temporary table is specified by the session, and ORACLE will truncate the table when the session is interrupted.

 

 

Temporary table feature description

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

b. Temporary tables do not require DML locks

c. Temporary tables can be indexed and views can be built on the basis of temporary tables

D. Indexes on temporary tables are also temporary and are 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 the definition of temporary tables, but you cannot export data

 

 

 

Session-level temporary table means that the data in the temporary table only exists in the session life cycle. When the user exits the session and ends, Oracle automatically clears the data in the temporary table.

A transaction-level temporary table means that the data in the temporary table exists only during the life cycle of the transaction. When a transaction ends (commit or rollback), Oracle automatically clears the data in the temporary table.

 

The data in the temporary table is only valid for the current session, each session has its own temporary data, and cannot access the data in the temporary table of other sessions. therefore,

Temporary tables do not require DML locks. When a session ends (the user exits normally and the ORACLE instance crashes when the user exits abnormally) or when a transaction ends, Oracle's

The table executes the TRUNCATE statement to clear the temporary table data. But it will not clear the data in the temporary table of other sessions.

 

You can index temporary tables and create views on temporary tables. Similarly, indexes built on temporary tables are also temporary and are only valid for the current session or transaction. 

Temporary tables can have triggers.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326245253&siteId=291194637