Oracle 11g笔记——临时表

来源:互联网 发布:工作淘宝客服怎么样 编辑:程序博客网 时间:2024/06/04 19:30

一、临时表
临时表是指表中的数据是临时存在的。临时表的数据只存在一次会话或一个事务中,而临时表的定义永久存在数据字典中。
我们可以用SQL语句CREATE GLOBAL TEMPORARY TABLE创建临时表。分类:
1、会话型临时表(Session-Specific),会话型的临时表的数据只存在会话期间,如果用户退出登录,Oracle会自动删除临时表中的数据。
2、事务型临时表(Transaction-Specific),事务型的临时表的数据只存在事务期间,如果事务结束,Oracle将自动删除临时表中的数据

示例:
创建事务型临时表,注:不能指定该表的表空间,默认为临时表空间
create blobal temporary table admin_work_area
(startdate date,
enddate date,
class char(I20))
on commit delete rows;

创建会话型临时表,注:不能指定该表的表空间,默认为临时表空间
create blobal temporary table admin_work_area
(startdate date,
enddate date,
class char(I20))
on commit preserve rows;

删除会话型临时表
SQL>truncate table tb_temp1;     -----消除会话与临时表的绑定
SQL>drop table tb_temp1;

删除事务型临时表
SQL>commit;     -----消除会话与临时表的绑定
SQL>drop table tb_temp2;

查看临时表的类型
SQL>select table_name,temporary,duration from user_tables where temporary='y';

 

0 0
原创粉丝点击