摘自:
http://docs.oracle.com/cd/E11882_01/server.112/e41084/statements_7002.htm#SQLRF01402
例子:
The following statement creates a temporary table today_sales for use by sales representatives in the sample database.
Each sales representative session can store its own sales data for the day in the table. The temporary data is deleted at the end of the session.
CREATE GLOBAL TEMPORARY TABLE today_sales ON COMMIT PRESERVE ROWS AS SELECT * FROM scott.emp where rownum<2;
DELETE ROWS 的含义: DELETE ROWS Specify DELETE ROWS for a transaction-specific temporary table. This is the default. Oracle Database will truncate the table (delete all its rows) after each commit.
PRESERVE ROWS 的含义 PRESERVE ROWS Specify PRESERVE ROWS for a session-specific temporary table. Oracle Database will truncate the table (delete all its rows) when you terminate the session.
Specify GLOBAL TEMPORARY to indicate that the table is temporary and that its definition is visible to all sessions with appropriate privileges.
The data in a temporary table is visible only to the session that inserts the data into the table.
When you first create a temporary table, its table metadata is stored in the data dictionary, but no space is allocated for table data.
Space is allocated for the table segment at the time of the first DML operation on the table.
The temporary table definition persists in the same way as the definitions of regular tables,
but the table segment and any data the table contains are either session-specific or transaction-specific data.
You specify whether the table segment and data are session- or transaction-specific with the ON COMMIT keywords.
You can perform DDL operations (such as ALTER TABLE, DROP TABLE, CREATE INDEX) on a temporary table only when no session is bound to it.
A session becomes bound to a temporary table by performing an INSERT operation on the table.
A session becomes unbound to the temporary table by issuing a TRUNCATE statement or at session termination,
or, for a transaction-specific temporary table, by issuing a COMMIT or ROLLBACK statement.