I created a global temp table using the following DDL:
CREATE GLOBAL TEMPORARY TABLE MY_TEMP_TABLE
(
column1 NUMBER,
column2 NUMBER
) ON COMMIT PRESERVE ROWS
Then I put some data into it and can read it fine.
I close my SQL client session and reopened it and the table is still there but has no data.
Am I correct in my observation that global temp tables persist between sessions just like regular permanent tables yet the data within them is lived only as long as the session in which it is populated?
Thanks
Correct.
A global temporary table exists forever, just like any other database object. It is created when you install your application (not at runtime) just like any other database object.
If you specify
ON COMMIT PRESERVE ROWS, the data persists for the lifetime of the session (and is only visible to the session that inserted it). If you specifyON COMMIT DELETE ROWS, the data persists only for the lifetime of the transaction (and is only visible to the transaction that inserted it).