重庆思庄Oracle、Redhat认证学习论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 865|回复: 0
打印 上一主题 下一主题

[参考文档] Oracle全局临时表和私有临时表

[复制链接]
跳转到指定楼层
楼主
发表于 2023-5-12 09:47:55 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
Oracle 全局临时表以下简称GTT(Global Temporary Table),私有临时表以下简称PTT(Private Temporary Table)。

GTT和PTT的主要区别如下:
    GTT更早。GTT是8i就有的特性,PTT是18c才有的特性。
    GTT和PTT的数据都是会话私有的,而且会话结束后数据就没有了,但GTT的定义是全局的。
    事务提交时,GTT可以选择是否保留数据,PTT可以选择是否保留定义。
    GTT的表定义是所有会话共享的;PTT的表定义是会话私有的。


临时表的语法帮助参见官方文档。
https://docs.oracle.com/en/datab ... f/CREATE-TABLE.html


GLOBAL TEMPORARY

    Specify GLOBAL TEMPORARY to create a temporary table, whose 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 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 clause.
    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 with an INSERT operation on the table. A session becomes unbound to a temporary table with a TRUNCATE statement or at session termination, or, for a transaction-specific temporary table, by issuing a COMMIT or ROLLBACK statement.

PRIVATE TEMPORARY

    Specify PRIVATE TEMPORARY to create a private temporary table.
    A private temporary table differs from a temporary table in that its definition and data are visible only within the session that created it. Use the ON COMMIT clause to define the scope of a private temporary table: either transaction or session. The ON COMMIT clause used with the keywords DROP DEFINITION creates a transaction-specific table whose data and definition are dropped when the transaction commits. This is the default behavior. The ON COMMIT clause used with keywords PRESERVE DEFINITION creates a session-specific table whose definition is preserved when the transaction commits. See here for usage details of theON COMMIT clause.
    Three DDL statements are supported for private temporary tables: CREATE, DROP, and TRUNCATE.

非SYS用户才可创建临时表




分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 支持支持 反对反对
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|手机版|小黑屋|重庆思庄Oracle、Redhat认证学习论坛 ( 渝ICP备12004239号-4 )

GMT+8, 2024-5-3 08:31 , Processed in 0.088514 second(s), 20 queries .

重庆思庄学习中心论坛-重庆思庄科技有限公司论坛

© 2001-2020

快速回复 返回顶部 返回列表