oracle 临时表的数据是放在内存,还是放在硬盘上?

exchanger 2003-09-26 10:21:12
请问,用CREATE GLOBAL TEMPORARY TABLE TAB_2 AS SELECT * FROM TAB_1 建立的临时表,它的数据是放在内存,还是放在硬盘上?
...全文
404 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
daydayupliq 2003-09-26
  • 打赏
  • 举报
回复
Here is another feature I found interesting that was introduced in Oracle 8i. Temporary tables, yep temporary tables. You may say, whats the big deal, I was creating temporary tables from before, whats new now. These temporary tables have a global definition. When a user inserts rows in a session, those rows are only visible to that session and the rows are only available until the transaction or the session is ended based on how the table has been defined. Confused....Read On...

Temporary Tables

Oracle 8i introduces a new concept called global temporary tables. This version only provides global temporary tables and local tables are expected in the future. These are like normal tables but the segment is created only when the data is inserted and hence temporary in nature.


create global temporary table dbatest
( c1 number, c2 number);

The above statement creates a table whose definition is visible to all the sessions but the data is visible to only the session that has created it. Temporary tables can be used by developers to store session / transaction specific data that can be discarded as soon as the session/transaction ends. When a truncate is issued on this table, only data related to that particular session is truncated.

The above code creates a table named dbatest. When data is inserted into this table the data persists either at the session or transaction level based on how "On Commit" parameter is specified. On commit can be specified as "delete rows" or "preserve rows". Delete Rows seems to be the default.

Create global temporary table dbatest
(
c1 number,
c2 number
) on commit delete rows;

In the above table, as soon as the user ends the transaction by issuing a commit statement, the data in the temporary table is deleted ( truncated ).

Create global temporary table dbatest
(
c1 number,
c2 number
) on commit preserve rows;

The above statement causes the creation of a table that will keep its rows even after the transaction is committed. If the user inserts rows into the above table and then commits the data, the data that was inserted will exist until the session is ended.

Restrictions

Temporary tables cannot contain nested tables or varray types or they cannot be partitioned, index-organized or clustered. They cannot be used in parallel DML or parallel queries and distributed transactions are not supported on these tables.



hdkkk 2003-09-26
  • 打赏
  • 举报
回复
Temporary tables use temporary segments. Unlike permanent tables, temporary
tables and their indexes do not automatically allocate a segment when they are
created
exchanger 2003-09-26
  • 打赏
  • 举报
回复
既然和一般的表一样,那为什么需要临时表呢?
yuaiwu 2003-09-26
  • 打赏
  • 举报
回复
硬盘上,和一般的表一样

3,491

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 高级技术相关讨论专区
社区管理员
  • 高级技术社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧