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 that the data should be deleted at the end of the transaction.CREATE GLOBAL TEMPORARY TABLE my_temp_table ( column1 NUMBER, column2 NUMBER ) ON COMMIT DELETE ROWS;
In contrast, the
ON COMMIT PRESERVE ROWS clause indicates that rows should be preserved until the end of the session.CREATE GLOBAL TEMPORARY TABLE my_temp_table ( column1 NUMBER, column2 NUMBER ) ON COMMIT PRESERVE ROWS;
Miscellaneous Features
- If the TRUNCATE statement is issued against a temporary table, only the session specific data is trucated. There is no affect on the data of other sessions.
- Data in temporary tables is stored in temp segments in the temp tablespace.
- Data in temporary tables is automatically deleted at the end of the database session, even if it ends abnormally.
- Indexes can be created on temporary tables. The content of the index and the scope of the index is the same as the database session.
- Views can be created against temporary tables and combinations of temporary and permanent tables.
- Temporary tables can have triggers associated with them.
- Export and Import utilities can be used to transfer the table definitions, but no data rows are processed.
- Statistics on temporary tables are common to all sessions. Oracle 12c allows session specific statistics.
- There are a number of restrictions related to temporary tables but these are version specific.
Note:-
1-> You can not specify a tablespace with global temporary tables. GTT's are built in the TEMP tablespace.
Syntax:-
----------------
CREATE GLOBAL TEMPORARY TABLE "XXGL"."XXGL_DAS2_CODE_COMBINATIONS"
( "CODE_COMBINATION_ID" NUMBER(15,0) NOT NULL ENABLE,
"SEGMENT3" VARCHAR2(25 BYTE),
"SEGMENT7" VARCHAR2(25 BYTE),
"SEGMENT4" VARCHAR2(25 BYTE),
"DAS2_CODE" VARCHAR2(15 BYTE),
"VENDOR_SITE_ID" NUMBER
) ON COMMIT PRESERVE ROWS ;
CREATE INDEX "XXGL"."XXGL_DAS2_CODE_COMBINATIONS_N1" ON "XXGL"."XXGL_DAS2_CODE_COMBINATIONS" ("CODE_COMBINATION_ID") ;