Oracle Global Temporary Tables

Oracle support two types of temporary tables.

Global Temporary Tables : Available since Oracle 8i and subject of this article.
Private Temporary Tables : Available since Oracle 18c 

Creation of Global Temporary Tables
The data in a global temporary table is private, such that data inserted by a session can only be accessed by that session.
The session-specific rows in a global temporary table can be preserved for the whole session,
or just for the current transaction.

The ON COMMIT DELETE ROWS clause indicates the data should be deleted at the end
of the transaction, or the end of the session.

Example :

CREATE GLOBAL TEMPORARY TABLE sample_temp_table (
  ID           NUMBER,
  DESC     VARCHAR2(20)
)
ON COMMIT DELETE ROWS; 

insert into sample_temp_table(ID,DESC) values(100,'Student 100 '); 

SELECT COUNT(*) FROM sample_temp_table;

Result :-  1

commit;

SELECT COUNT(*) FROM sample_temp_table;

Result :-  0

Comments