关于 oracle 临时表 ORA-14452

 

关于 oracle 临时表 ORA-14452

--总结:不管事务级还是会话级的临时表,都需要所有会话解除绑定,才能drop,解除绑定的办法就是清空每个会话的数据
--清空数据的办法:事务级别的临时表:commit/truncate table;会话级的临时表:truncate table ;
--注意,事务级临时表:不能用delete所有数据 然后commit这种方式清空,必须用truncate table,才能解除该会话同临时表的绑定
--事务级:on commit delete rows;
--会话级:on commit preserve rows;
--ORA-14452: attempt to create, alter or drop an index on temporary table already in use避免此错误就是解除所有数据绑定,清空每个使用的数据。
--测试会话级临时表
sqlplus
sql> set sqlprompt "SESSION 1"
SESSION 1> CREATE GLOBAL TEMPORARY TABLE TMP01 (int_id integer) ON COMMIT PRESERVE ROWS;

Table created.

SESSION 1> insert into tmp01 values (11);

1 row created.

SESSION 1> select * from tmp01;

INT_ID
----------
11

SESSION 1> commit;

Commit complete.

SESSION 1> select * from tmp01;

INT_ID
----------
11
SESSION 2> insert into tmp01 values(22);

1 row created.

SESSION 2> select * from tmp01;

INT_ID
----------
22

SESSION 1> truncate table tmp01;

Table truncated.

SESSION 1> drop table tmp01;
drop table tmp01
*
ERROR at line 1:
ORA-14452: attempt to create, alter or drop an index on temporary table already
in use

SQL> truncate table tmp01;

Table truncated.

SESSION 1> drop table tmp01;

Table dropped.


--测试事务临时表
SESSION 1> CREATE GLOBAL TEMPORARY TABLE TMP01 (int_id integer) ON COMMIT delete rows;

Table created.

SESSION 1> insert into tmp01 values (11);

1 row created.

SESSION 1> select * from tmp01;

INT_ID
----------
11
SESSION 2> insert into tmp01 values(22);

1 row created.

SESSION 2> select * from tmp01;

INT_ID
----------
22


SESSION 1> commit;

Commit complete.

SESSION 1> select * from tmp01;

no rows selected

SESSION 1> select * from tmp01;

no rows selected

SESSION 1> drop table tmp01;
drop table tmp01
*
ERROR at line 1:
ORA-14452: attempt to create, alter or drop an index on temporary table already
in use

SESSION 2> drop table tmp01;

Table dropped.


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值