oracle创建临时表

临时表:像普通表一样,有结构,但是对数据的管理上不一样,临时表存储事务或会话的中间结果集,临时表中保存的数据只对当前 会话可见,所有会话都看不到其他会话的数据,即使其他会话提交了,也看不到。临时表不存在并发行为,因为他们对于当前会话都是独立的。(它默认是事务级别的)

在oracle中临时表可分为会话级临时表和事务级别临时表。

临时表的作用:对于庞大的数据我们只要查询其中一小部分结果集这样我们可以借助临时表。

1.会话级别临时表

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

create global temporary table aaa(id number) on commit oreserve rows;

insert into aaa values(100);

select * from aaa;

这是当你在打开另一个会话窗口的时候再次查询,表内的数据就查询不到了。

2.事务级别的临时表

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

insert into bbb values(200);

select * from bbb;

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

默认下的:

SQL> create global temporary table aaa as select * from dba_objects;

Table created.

SQL> select * from aaa;--没有数据,因为省掉了on commit delete rows

猜你喜欢

转载自blog.csdn.net/qq_32445015/article/details/86218211