设为首页 加入收藏

TOP

Oracle 临时表的使用
2019-02-16 00:08:20 】 浏览:77
Tags:Oracle 临时 使用

会话级的临时表在整个会话期间都存在,直到会话结束;事务级别的临时表数据在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 临时表名;


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇MySQL 之 MERGE 存储引擎 下一篇MySQL列名中包含斜杠或者空格的处..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目