Oracle 18c 新特性-私有临时表

说明

私有临时表会在事务或会话结束时自动删除。私有临时表存储在内存中,仅对创建它的会话可见。

有临时表仅作用在会话或事务上,从而在应用程序编码方面提供了更大的灵活性,从而使代码维护更加容易,并具有更好的即时可用功能。私有临时表命名必须以ORA$PTT_为前缀,是由参数private_temp_table_prefix控制。

私有临时表适用场景:

a) When an application stores temporary data in transient tables that are populated once, read few times, and then dropped at the end of a transaction or session

b) When a session is maintained indefinitely and must create different temporary tables for different transactions

c) When the creation of a temporary table must not start a new transaction or commit an existing transaction

d) When different sessions of the same user must use the same name for a temporary table

e) When a temporary table is required for a read-only database

创建私有临时表

默认情况下,私有临时表存储在创建用户的默认临时表空间中,也可以指定其他临时表空间。

ON COMMIT SettingImplications
DROP DEFINITIONThis creates a private temporary table that is transaction specific. All data in the table is lost, and the table is dropped at the end of transaction.
PRESERVE DEFINITIONThis creates a private temporary table that is session specific. All data in the table is lost, and the table is dropped at the end of the session that created the table.

创建一个用于事务的私有临时表

CREATE PRIVATE TEMPORARY TABLE ORA$PTT_sales_ptt_transaction
    (time_id      DATE,
     amount_sold  NUMBER(10,2))
   ON COMMIT DROP DEFINITION;

创建一个用于会话的私有临时表

CREATE PRIVATE TEMPORARY TABLE ORA$PTT_sales_ptt_session
    (time_id      DATE,
     amount_sold  NUMBER(10,2))
   ON COMMIT PRESERVE DEFINITION;

注:SYS用户无法创建私有临时表,原因不清楚。

请查看文档:https://www.cndba.cn/Expect-le/article/2949

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值