基於會話的全局臨時表(on commit preserve rows)
基於事務的全局臨時表(on commit delete rows)
set autotrace off;
(1)建立表
//建立臨時會話表
create global temporary table tmp_session1 on commit preserve rows as select * from dba_objects where 1=0;
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
//建立事務臨時表
create global temporary table tmp_trans1 on commit delete rows as select * from dba_objects where 1=0;
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)插入數據
//向臨時會話表插入數據
insert into tmp_session1 select * from dba_objects;
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
//向臨時事務表插入數據
insert into tmp_trans1 select * from dba_objects;
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
測試:
//在事務上
select count(*) from tmp_trans;
COUNT(*)
----------
72539
commit;
select count(*) from tmp_trans;
COUNT(*)
----------
0
//在會話上
select count(*) from tmp_session1;
COUNT(*)
----------
72537
commit;
select count(*) from tmp_session1;
COUNT(*)
----------
72537
sql guoyf/guoyf
Connected.
Session altered.
LISN@orcl>select count(*) from tmp_session1;
select count(*) from tmp_session1;
COUNT(*)
----------
0
基於會話的臨時表:
全局臨時表特徵:
(1)基於會話的全局臨時表特徵:基於會話的全局臨時表則是session連接退出後,臨時記錄自動刪除,無需手動去操做,針對不一樣session訪問全局臨時表,看到的結果是不一樣。
(2)基於事務的全局臨時表在commit或者session連接退出後,臨時表記錄自動刪除。
sql