(轉)Oracle 暫存資料表用法

來源:互聯網
上載者:User

標籤:style   blog   http   color   io   ar   資料   div   cti   

本文轉載自:http://www.iteye.com/topic/371390

ORACLE的暫存資料表在應用系統中有很大的作用,它可以讓使用者只能夠操作各自的資料中而互不干擾,不用擔心會破壞或影響其他SESSION/TRANSACTION的資料,這也是資料安全的一種解決方案。
暫存資料表分為SESSION、TRANSACTION兩種,SESSION級的暫存資料表資料在整個SESSION都存在,直到結束此次SESSION;而TRANSACTION級的暫存資料表資料在TRANACTION結束後消失,即COMMIT/ROLLBACK或結束SESSION都會清除TRANACTION暫存資料表資料。
兩種暫存資料表的文法:
    create global temporary table 暫存資料表名 on commit preserve|delete rows  用preserve時就是SESSION級的暫存資料表,用delete就是TRANSACTION級的暫存資料表

一、SESSION級暫存資料表
1、建立暫存資料表

    create global temporary table temp_tbl(col_a varchar2(30))      on commit preserve rows  

2、插入資料

    insert into temp_tbl values(‘test session table‘)  

3、提交commit;
4、查詢資料

    select *from temp_tbl  

可以看到資料‘test session table‘記錄還在。
結束SESSION,重新登入,再查詢資料select *from temp_tbl,這時候記錄已不存在,因為系統在結束SESSION時自動清除記錄
二、TRANSACTION級暫存資料表
1、建立暫存資料表

    create global temporary table temp_tbl(col_a varchar2(30))      on commit delete rows  

2、插入資料

    insert into temp_tbl values(‘test transaction table‘)  

3、提交
    commit
4、查詢資料

    select *from temp_tbl  

這時候可以看到剛才插入的記錄‘test transaction table‘已不存在了;同樣,如果不提交而直接結束SESSION,重新登入記錄也不存在

(轉)Oracle 暫存資料表用法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.