ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 临时表

临时表

原创 Linux操作系统 作者:sniper_bullet 时间:2012-11-21 23:18:22 0 删除 编辑
CREATE GLOBAL TEMPORARY TABLE ...
[ON COMMIT PRESERVE ROWS ]
CREATE GLOBAL TEMPORARY TABLE ...
[ON COMMIT DELETE ROWS ]
临时表中的可选项:
ON COMMIT PRESERVE ROWS ,事务提交自后会oracle会清除临时表中的数据
ON COMMIT PRESERVE ROWS ,事务提交之后会保留数据,知道session结束。
 
其中发现一点,如果临时表是以ON COMMIT PRESERVE ROWS创建,如果想对表进行ddl操作,会提示如下错误:
All the sessions using the session-specific temporary table have
           to truncate table and all the transactions using transaction
           specific temporary table have to end their transactions.
提示中指出,所有用到这个临时表的session需要抽取表中数据,或者所有的特定事务完成才可以做drop。
 
摘自toad knowledge xpert 帮助:
For a session-specific temporary table, a session gets bound to the temporary table with the first insert in the table in the session. This binding goes away at the end of the session or by issuing a TRUNCATE of the table in the session
即truncate table tablename后
 
下面摘除完整的说明:
You can create indexes on temporary tables same as you would on permanent tables. 
 
  • For a session-specific temporary table, a session gets bound to the temporary table with the first insert in the table in the session. This binding goes away at the end of the session or by issuing a TRUNCATE of the table in the session. 
     
  • For a transaction-specific temporary table, a session gets bound to the temporary table with the first insert in the table in the transaction. The binding goes away at the end of the transaction. 
     
  • DDL operations (except TRUNCATE) are allowed on an existing temporary table only if no session is currently bound to that temporary table. Unlike permanent tables, temporary tables and their indexes do not automatically allocate a segment when they are created. Instead, segments are allocated when the first INSERT (or CREATE TABLE AS SELECT) is performed. This means that if a SELECT, UPDATE, or DELETE is performed before the first INSERT, the table appears to be empty.
     
  • Temporary segments are de-allocated at the end of the transaction for transaction-specific temporary tables and at the end of the session for session-specific temporary tables. If you rollback a transaction, the data you entered is lost, although the table definition persists. 
     
  • You cannot create a table that is simultaneously both transaction- and session-specific. A transaction-specific temporary table allows only one transaction at a time. If there are several autonomous transactions in a single transaction scope, each autonomous transaction can use the table only as soon as the previous one commits. 
     
  • The data in a temporary table is, by definition, temporary, so backup and recovery of a temporary table's data is not available in the event of a system failure. To prepare for such a failure, you should develop alternative methods for preserving temporary table data.
  •  

    来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/27207674/viewspace-749716/ ,如需转载,请注明出处,否则将追究法律责任。

    上一篇: 没有了~
    下一篇: 关于临时表二
    请登录后发表评论 登录
    全部评论

    注册时间:2012-07-28

    • 博文量
      5
    • 访问量
      2043