首页 » ORACLE 9i-23c » oracle 临时表、临时表空间、临时表空间组用法区别

oracle 临时表、临时表空间、临时表空间组用法区别

临时表

Oracle中的临时表是全局的,需要在数据库设计时创建完成,而不是程序使用时。每个登陆用户都使用这一个相同的临时表,但互相之间看不到彼此的数据,也就是说临时表是会话独立的。并且不产生日志。
Oracle 的临时表分为事务型和会话型。
事务型临时表就是指在事务处理过程中插入的记录只在事务提交或回滚之前有效,一旦事务完成,表中的记录便被自动清除。
会话型临时表指临时表中的数据在本次会话期间一直有效,直到会话结束。会话结束后表中针对此次会话的数据会自动清空。

创建

CREATE GLOBAL TEMPORARY TABLE  tmp_test1 (

id int,

name varchar2(10)

) ON COMMIT PRESERVE(DELETE) ROWS ;

临时表空间

temporary tablespace是用户在做数据排序都操作时临时存放的表空间

查询 v$tempfile\ dba_temp_file

每个用户都有一个默认临时表空间,在创建用户时如果没指定将使用oracle 数据库设置的默认临时表空间,查询方法是:

select property_name,property_value from database_properties where property_value=‘TEMP’

创建例子

create temporary tablespace test2 tempfile ‘/u01/app/oracle/oradata/ORCL/datafile/temp2.tmp’ size 50m autoextend on;

设为数据库默认

SQL> aLTER DATABASE DEFAULT TEMPORARY TABLESPACE test2;

Database altered.

设置后以前未指定的用户临时表空间都为最新

临时表空间组

在 oracle 10g 中,可以创建多个临时表空间,并把它们组成一个临时表空间组,这样应用数据用于排序时可以使用组里的多个临时表空间,一个临时表空间组至少有一个临时表空间,其最大个数没有限制,组的名字不能和其中某个表空间的名字相同。数据文件表空间不可以创建这类似的表空间组

临时表空间组是在创建临时表空间时通过指定group字句创建的,如果删除组中的全部
临时表空间,那么这个组也将消失。

创建例子

SQL> create temporary tablespace tempts1 tempfile
2  ‘/home/oracle/temp1_02.dbf’ size 2M tablespace group group1;
Tablespace created
SQL> create temporary tablespace tempts2 tempfile
2  ‘/home/oracle/temp2_02.dbf’ size 2M tablespace group group2;
Tablespace created

查询

select * from dba_tablespace_groups;

使用临时表空间组,有如下的优点:
1.避免当临时表空间不足时所引起的磁盘排序问题;
2.当一个用户同时有多个会话时,可以使得它们使用不同的临时表空间;
3.使得并行的服务器在单节点上,能使用多个临时表空间 .

打赏

目前这篇文章有1条评论(Rss)评论关闭。

  1. Majorie Meisenburg | #1
    2011-12-21 at 07:04

    Excellent goods from you, man. I’ve be aware your stuff previous to and you are just too excellent. I really like what you have obtained right here, really like what you’re saying and the best way during which you are saying it. You’re making it entertaining and you continue to care for to stay it sensible. I can not wait to learn far more from you. This is really a terrific web site.