问题
Can someone please tell me: how long will data be there in a Global Temporary table?
回答1:
They can be SESSION based (data survives a commit but not a disconnect/reconnect). They can also be TRANSACTION based (data disappears after a commit).
This creates a transaction based temp table:
create global temporary table temp_table_transaction on commit delete rows ...
This creates a session based temp table:
create global temporary table temp_table_transaction on commit preserve rows ...
回答2:
When you create a temporary table you have two options for data persistence:
ON COMMIT DELETE ROWS(default) andON COMMIT PRESERVE ROWS
If you don't specify a persistence clause, or specify ON COMMIT DELETE ROWS, the data in the table will be transaction-specific (it will be deleted upon commit or rollback).
If you specify ON COMMIT PRESERVE ROWS, the data will stay until the end of your session.
回答3:
If the table was created with "on commit preserve rows" then data will remain until the end of the current session. If it was created with "on commit delete rows" then it will remain until the next commit or rollback.
来源:https://stackoverflow.com/questions/5017641/duration-of-data-in-a-global-temporary-table