zoukankan      html  css  js  c++  java
  • Oracle两种临时表的创建与使用详解

    ORACLE数据库除了可以保存永久表外,还可以建立临时表temporary tables。这些临时表用来保存一个会话SESSION的数据,或者保存在一个事务中需要的数据。当会话退出或者用户提交commit和回滚rollback事务的时候,临时表的数据自动清空,但是临时表的结构以及元数据还存储在用户的数据字典中。


    分类:
    1.会话级临时表
    会话级临时表是指临时表中的数据只在会话生命周期之中存在,当用户退出会话结束的时候,Oracle自动清除临时表中数据。

    格式:
    Create Global Temporary Table Table_Name
    (
    Col1 Type1,
    Col2 Type2
    ...
    )
    On Commit Preserve Rows;
    2.事务级临时表
    事务级临时表是指临时表中的数据只在事务生命周期中存在。
    Create Global Temporary Table Table_Name
    (
    Col1 Type1,
    Col2 Type2
    ...
    )
    On Commit Delete Rows;
    当一个事务结束(commit or rollback),Oracle自动清除临时表中数据。


    下面在Oracle 10g中演示了临时表的创建与使用:


    1.创建事务级临时表,插入一条数据,并查询:

    create global temporary table transaction_temp_tb (col1 varchar(20)) on commit delete rows;
    insert into  transaction_temp_tb values('test');
    select * from  transaction_temp_tb;

     2.执行commit或者rollback操作,临时表内数据就被清空,但表结构依然存在:

     3.创建一个会话级临时表,插入一条数据,并查询:

    create global temporary table session_temp_tb (col1 varchar(20)) on commit preserve rows;
    insert into session_temp_tb values('test');
    select * from session_temp_tb;

     4..执行commit或者rollback操作,表内数据依然存在,新建一个命令窗口(相当于开启了一个新的会话),表内的数据就查询不到了:

     5.如果创建会话临时表的会话没有结束,则无法删除此临时表,因为临时表,还在使用之中,但是结束会话(关闭创建会话级临时表的命令窗口)后就可以删除了:

     

    好的代码像粥一样,都是用时间熬出来的
  • 相关阅读:
    Calling a parent window function from an iframe
    JSON with Java
    Posting array of JSON objects to MVC3 action method via jQuery ajax
    What's the difference between jquery.js and jquery.min.js?
    jquery loop on Json data using $.each
    jquery ui tabs详解(中文)
    DataTables warning requested unknown parameter
    Datatables 1.10.x在命名上与1.9.x
    jQuery 1.x and 2.x , which is better?
    DataTabless Add rows
  • 原文地址:https://www.cnblogs.com/jijm123/p/15499670.html
Copyright © 2011-2022 走看看