Oracle建立基於事務和基於會話的暫存資料表及暫存資料表建索引的實驗

來源:互聯網
上載者:User

Oracle的暫存資料表只存在於某個回話或者事務的生命週期裡,此時暫存資料表中的資料只對當前這個會話可見。

當會話退出或者使用者提交commit和復原rollback事務的時候,暫存資料表的資料自動清空,但是暫存資料表的結構以及中繼資料還儲存在使用者的資料字典中。

暫存資料表的定義對所有會話SESSION都是可見的,但是表中的資料只對當前的會話或者事務有效.
暫存資料表經常被用於存放一個操作的中間資料(資料處理的中間環節)。

暫存資料表由於不產生redo,能夠提高資料操作的效能。

暫存資料表不會產生鎖和等待。


實驗如下:

1.ON COMMIT DELETE ROWS 基於事務的暫存資料表,暫存資料表中的資料是基於事務的,當事物提交或者復原時,暫存資料表中的資料將被清空

12:35:26 SQL> create global temporary table temp1 on commit delete rows as select * from dba_extents;
Table created
14:06:29 SQL> select count(*) from temp1;
COUNT(*)
----------
0
14:08:16 SQL> insert into temp1 select * from dba_extents;
9221 rows inserted
14:09:02 SQL> select count(*) from temp1;
COUNT(*)
----------
9221
14:09:20 SQL> commit;
Commit complete
14:09:24 SQL> select count(*) from temp1;
COUNT(*)
----------
0
14:09:27 SQL> select * from temp1;
OWNER SEGMENT_NAME PARTITION_NAME SEGMENT_TYPE TABLESPACE_NAME EXTENT_ID FILE_ID BLOCK_ID BYTES BLOCKS RELATIVE_FNO
------------------------------ -------------------------------------------------------------------------------- ------------------------------ ------------------ ------------------------------ ---------- ---------- ---------- ---------- ---------- ------------

2.PRESERVE ROWS 基於會話的暫存資料表,暫存資料表中的資料基於會話,當會話結束時,暫存資料表中的資料被清空。

14:15:16 SQL> create global temporary table temp2 on commit preserve rows as select * from dba_extents;
Table created
14:15:39 SQL> select count(*) from temp2;
COUNT(*)
----------
9221
14:16:19 SQL> insert into temp2 select * from dba_extents;
9222 rows inserted
14:16:58 SQL> select count(*) from temp2;
COUNT(*)
----------
18443
14:17:15 SQL> commit;
Commit complete
14:17:18 SQL> select count(*) from temp2;
COUNT(*)
----------
18443
14:17:19 SQL>

再開啟一個會話進行查詢:
SQL> select count(*) from temp2;
COUNT(*)
----------
0
SQL> select * from temp2;
OWNER SEGMENT_NAME PARTITION_NAME SEGMENT_TYPE TABLESPACE_NAME EXTENT_ID FILE_ID BLOCK_ID BYTES BLOCKS RELATIVE_FNO
------------------------------ -------------------------------------------------------------------------------- ------------------------------ ------------------ ------------------------------ ---------- ---------- ---------- ---------- ---------- ------------
SQL>

更多詳情見請繼續閱讀下一頁的精彩內容:

Oracle 資料表空間與資料檔案

Oracle 暫存資料表空間的管理與受損恢複

Oracle 徹底 kill session

  • 1
  • 2
  • 下一頁

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.