zoukankan      html  css  js  c++  java
  • oracle 临时表的使用

    在oracle中,临时表分为会话级别(session)和事务级别(transaction)两种。

    会话级的临时表在整个会话期间都存在,直到会话结束;事务级别的临时表数据在transaction结束后消失,即commit/rollback或结束会话时,会清除临时表数据。

      1、事务级临时表  on commit delete rows;      当COMMIT的时候删除数据(默认情况)
      2、会话级临时表  on commit preserve rows;  当COMMIT的时候保留数据,当会话结束删除数据

    1.会话级别临时表

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

    创建方式1:

    create global temporary table temp1(id number) on commit PRESERVE rows;

    insert into temp1values(100);

    select * from temp1;

    创建方式2:

    create global temporary table temp1 ON COMMIT PRESERVE ROWS    as  select id from 另一个表;

    select * from temp1;

    这个时候,在当前会话查询数据就可以查询到了,但是再新开一个会话窗口查询,就会发现temp1是空表。

    2.事务级别的临时表

    创建方式1:

    create global temporary table temp2(id number) on commit delete rows;

    insert into temp2 values(200);

    select * from temp2;

    创建方式2:

    create global temporary table temp2 as select  id  from 另一个表;(默认创建的就是事务级别的)

    select * from temp2;

    这时当你执行了commit和rollback操作的话,再次查询表内的数据就查不到了。

    3.oracle的临时表创建完就是真实存在的,无需每次都创建。

    若要删除临时表可以:

    truncate table 临时表名;
    drop table 临时表名;

  • 相关阅读:
    开发一个delphi写的桌面图标管理代码
    web颜色转换为delphi
    delphi RGB与TColor的转换
    用Delphi制作仿每行带按钮的列表
    Delphi 之 编辑框控件(TEdit)
    numEdit
    DropDownList添加客户端下拉事件操作
    19个必须知道的Visual Studio快捷键
    asp.net线程批量导入数据时通过ajax获取执行状态
    详解JQuery Ajax 在asp.net中使用总结
  • 原文地址:https://www.cnblogs.com/hahahayang/p/10382732.html
Copyright © 2011-2022 走看看