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

  • 相关阅读:
    服务器安装宝塔面板
    CentOS7操作SSH/SSHD服务(查看/启动/重启/自启)
    CentOS服务器升级Linux版本
    阿里云云服务器漏洞修复
    Linux服务器安装Docker
    服务器安装Nginx
    服务器端简单Demo
    实现博客内容折叠
    [转]珍惜时间,做好规划——致大学过半的你们
    【LeetCode】9. 回文数
  • 原文地址:https://www.cnblogs.com/hahahayang/p/10382732.html
Copyright © 2011-2022 走看看