Duration of data in a Global Temporary table?

孤人 提交于 2021-02-04 10:25:07

问题


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) and
  • ON 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!