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

  • 相关阅读:
    js 中常用的方法
    js中this的四种调用模式
    JS面向对象的几种写法
    js 中的算法题,那些经常看到的
    web页面的回流,认识与避免
    js中的预加载与懒加载(延迟加载)
    Web安全测试学习笔记-DVWA-存储型XSS
    Web安全测试学习笔记-DVWA-图片上传
    Web安全测试学习笔记-DVWA-盲注(使用sqlmap)
    Web安全测试学习笔记-DVWA-SQL注入-1
  • 原文地址:https://www.cnblogs.com/hahahayang/p/10382732.html
Copyright © 2020-2023  润新知