Oracle-----臨時會話與臨時事務的區別

全局臨時表包括:shell

基於會話的全局臨時表(commit preserve rows)c#

基於事務的全局臨時表(on commit delete rows)session

注意:實驗在兩個不一樣的會話作測試

(1)建立表ui

//建立臨時會話表
LISN@orcl>create global temporary table tmp_session1 on commit preserve rows as select * from dba_objects where 1=0;

LISN@orcl>select a.name,b.value from v$statname a join v$mystat b on a.statistic#=b.statistic# where a.name='redo size';
NAME								      VALUE
---------------------------------------------------------------- ----------
redo size							     100496

另外一個會話spa

//建立事務臨時表
LISN@orcl>create global temporary table tmp_trans1 on commit delete rows as select * from dba_objects where 1=0;

LISN@orcl>select a.name,b.value from v$statname a join v$mystat b on a.statistic#=b.statistic# where a.name='redo size';
NAME								      VALUE
---------------------------------------------------------------- ----------
redo size							      21912

(2)插入數據code

//向臨時會話表插入數據
LISN@orcl>insert into tmp_session1 select * from dba_objects;

LISN@orcl>select a.name,b.value from v$statname a join v$mystat b on a.statistic#=b.statistic# where a.name='redo size';
NAME								      VALUE
---------------------------------------------------------------- ----------
redo size							     512820

在臨時事務會話事務

//向臨時事務表插入數據
LISN@orcl>insert into tmp_trans1 select * from dba_objects;

LISN@orcl>select a.name,b.value from v$statname a join v$mystat b on a.statistic#=b.statistic# where a.name='redo size';
NAME								      VALUE
---------------------------------------------------------------- ----------
redo size							     434236

(3)測試it

//在事務上那個會話上io

LISN@orcl>select count(*) from tmp_trans;
  COUNT(*)
----------
     72539                            --注意有數據

LISN@orcl>commit;
commit;                               --提交一下

LISN@orcl>select count(*) from  tmp_trans; --注意提交後沒數據

  COUNT(*)
----------
	 0


//在會話上

LISN@orcl>select count(*) from tmp_session1;        --注意有數據
select count(*) from tmp_session1;

  COUNT(*)
----------
     72537

LISN@orcl>commit;                                    --提交一下
commit;

Commit complete.

LISN@orcl>select count(*) from tmp_session1;        --依然有數據
select count(*) from tmp_session1;

  COUNT(*)
----------
     72537

SYS@orcl>conn lisn/lisn                            --quit,從新連接
conn lisn/lisn
Connected.

Session altered.

LISN@orcl>select count(*) from tmp_session1;        --查詢無數據
select count(*) from tmp_session1;

  COUNT(*)
----------


基於會話的臨時表:


全局臨時表特徵:

(1)基於會話的全局臨時表特徵:基於會話的全局臨時表則是session連接退出後,臨時記錄自動刪除,無需手動去操做,針對不一樣session訪問全局臨時表,看到的結果是不一樣。

(2)基於事務的全局臨時表在commit或者session連接退出後,臨時表記錄自動刪除。


1.建立表

相關文章
相關標籤/搜索