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 临时表名;

  • 相关阅读:
    Ribbon 负载均衡搭建
    MicroService 微服务提供者搭建
    转 Spring boot 集成 Dubbo 快速搭建
    (转)Spring boot 集成Kafka
    转 Spring boot 集成ActiveMQ(包含双向队列实现)
    (转)异步实现服务器推送消息(聊天功能示例)
    (转)Spring boot 配置异步处理执行器
    (转)SSH框架快速搭建(Maven)
    (转)Hbase 操作工具类
    (转)Java AES加密算法工具类
  • 原文地址:https://www.cnblogs.com/hahahayang/p/10382732.html
Copyright © 2011-2022 走看看