1简介

ORACLE数据库除了可以保存永久表外,还可以建立临时表temporary tables。这些临时表用来保存一个会话SESSION的数据,或者保存在一个事务中需要的数据。当会话退出或者用户提交commit和回滚rollback事务的时候,临时表的数据自动清空(truncate),但是临时表的结构以及元数据还存储在用户的数据字典中。

In addition to permanent tables, Oracle can create temporary tables to hold session-private data that exists only forthe duration of a transaction orsession.

Temporary tables are supported by Oracle9i and Oracle8i.

2详细介绍

Oracle临时表分为 会话级临时表 和 事务级临时表。

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

事务级临时表是指临时表中的数据只在事务生命周期中存在。当一个事务结束(commit orrollback),Oracle自动清除临时表中数据。

临时表中的数据只对当前Session有效,每个Session都有自己的临时数据,并且不能访问其它Session的临时表中的数据。因此,临时表不需要DML锁。

The CREATE GLOBAL TEMPORARY TABLE statement creates a temporary table that can be transaction-specific orsession-specific. Fortransaction-specific temporary tables, data exists forthe duration of the transaction. Forsession-specific temporary tables, data exists forthe duration of the session. Data in a temporary table is private to the session. Each session can only see and modify its own data. DML locks are not acquired on the data of the temporary tables. The LOCK statement has no effect on a temporary table, because each session has its own private data.

DML操作的临时表不产生redo log重作日志,但会产生回滚日志Undo log;Undo的产生(rollback segment)会产生Redo log。

DML statements on temporary tables do not generate redo logs for the data changes. However, undo logs for the data and redo logs for the undo logs are generated.

当一个会话结束(用户正常退出 用户不正常退出 ORACLE实例崩溃)或者一个事务结束的时候,Oracle对这个会话的表执行 TRUNCATE 语句清空临时表数据.但不会清空其它会话临时表中的数据.

A TRUNCATE statement issued on a session-specific temporary table truncates data in its own session. It does not truncate the data of othersessions that are using the same table.

DML statements on temporary tables do not generateredo logs forthe data changes. However, undo logs forthe data andredo logs forthe undo logs are generated. Data from the temporary table is automatically dropped in the case of session termination, eitherwhen the userlogs off orwhen the session terminates abnormally such as during a session orinstance failure.

你可以索引临时表和在临时表基础上建立视图.同样,建立在临时表上的索引也是临时的,也是只对当前会话或者事务有效.临时表可以拥有触发器.

You can create indexes fortemporary tables using the CREATE INDEX statement. Indexes created on temporary tables are also temporary, and the data in the index has the same session ortransaction scope as the data in the temporary table.

You can create views that access both temporary and permanent tables. You can also create triggers on temporary tables.

空间分配Segment Allocation(v$sort_usage)

Temporary tables use temporary segments. Unlike permanent tables, temporary tables and their indexes do not automatically allocate a segment when they are created. Instead, segments are allocated when the firstINSERT(orCREATETABLE ASSELECT) is performed. This means that if aSELECT,UPDATE, orDELETEis performed before the firstINSERT, then the table appears to be empty.

Temporary segments are deallocated at the end of the transaction for transaction-specific temporary tables and at the end of the session for session-specific temporary tables.

临时表在一些版本中存在BUG可能产生过多的REDO LOG。eygle的站点

3建立临时表

临时表的定义对所有会话SESSION都是可见的,但是表中的数据只对当前的会话或者事务有效.

建立方法:

1)ON COMMIT DELETE ROWS定义了建立事务级临时表的方法.

CREATE GLOBAL TEMPORARY TABLE admin_work_area

(startdate DATE,

enddate DATE,

class CHAR(20))

ON COMMIT DELETE ROWS;

EXAMPLE:

SQL> CREATE GLOBAL TEMPORARY TABLE admin_work_area

2(startdate DATE,

3enddate DATE,

4class CHAR(20))

5ON COMMIT DELETE ROWS;

SQL> create table permernate( a number);

SQL> insert into admin_work_area values(sysdate,sysdate,'temperary table');

SQL> insert into permernate values(1);

SQL> commit;

SQL> select * from admin_work_area;

SQL> select* from permernate;

A

1

2)ON COMMIT PRESERVE ROWS 定义了创建会话级临时表的方法.

CREATE GLOBAL TEMPORARY TABLE admin_work_area

(startdate DATE,

enddate DATE,

class CHAR(20))

ON COMMIT PRESERVE ROWS;

EXAMPLE:

会话1:

SQL> drop table admin_work_area;

SQL> CREATE GLOBAL TEMPORARY TABLE admin_work_area

2(startdate DATE,

3enddate DATE,

4class CHAR(20))

5ON COMMIT PRESERVE ROWS;

SQL> insert into permernate values(2);

SQL> insert into admin_work_area values(sysdate,sysdate,'session temperary');

SQL> commit;

SQL> select * from permernate;

A

1

2

SQL> select * from admin_work_area;

STARTDATEENDDATECLASS

17-1ÔÂ -03 17-1ÔÂ -03 session temperary

会话2:

SQL> select * from permernate;

A

1

2

SQL> select * from admin_work_area;

未选择行.

会话2看不见会话1中临时表的数据.

oracle查询数据放入临时表,ORACLE Temporary Tables临时表更适合做插入和查询操作相关推荐

  1. SpringBoot将数据放入Excel里面通过浏览器直接下载到本地

    SpringBoot将数据放入Excel里面通过浏览器直接下载到本地 说明 依赖 代码 效果 说明 以前做java方面的导出下载的时候,都是先把数据导出到linux服务器里面的某个目录,然后才是通过浏 ...

  2. flink 处理迟到数据(Trigger、设置水位线延迟时间、允许窗口处理迟到数据、将迟到数据放入侧输出流、代码示例、迟到数据触发窗口计算重复结果处理)

    文章目录 前言 1.Trigger 2.处理迟到数据 2.1 设置水位线延迟时间 2.2 允许窗口处理迟到数据 2.3 将迟到数据放入侧输出流 3.实操 3.1 代码示例 3.2 中间遇到的异常 3. ...

  3. oracle修改数据文件存储位置,oracle 修改数据库文件位置

    Oracle 体系结构 Oracle 服务器 如图所示:由oracle实例(INSTANCE)和数据库(database)组成. 1) Instance 实例用于管理和调用数据库,是由oracle系统 ...

  4. vc++64位系统下long的长度为4个字节_新来的妹子把几百万数据放入了内存,系统立马爆了...

    点击上方蓝色字体,选择"标星公众号" 优质文章,第一时间送达 上一篇:这300G的Java资料是我师傅当年给我的,免费分享给大家 下一篇:这200G的Java实战资料是我师傅当年教 ...

  5. oracle备份数据表叫什么,oracle备份表和数据

    oracle 备份数据 如果备份表存在 原表t_base_employee,备份表t_base_employee20180718 insert into t_base_employee0718 sel ...

  6. mysql去重查询并将结果放入新表

    CREATE TABLE 表名 AS SELECT DISTINCT 字段 FROM 查询表名; # 将数据去重并放入新表中ALTER TABLE 表名 ADD id INT(11) PRIMARY ...

  7. 新来的妹子把几百万数据放入了内存,系统立马爆了

    点击上方蓝色字体,选择"标星公众号" 优质文章,第一时间送达 上一篇:这300G的Java资料是我师傅当年给我的,免费分享给大家 下一篇:这200G的Java实战资料是我师傅当年教 ...

  8. oracle常用数据统计,学习笔记:Oracle DBMS_STATS常用方法汇总 常用于收集统计oracle...

    天萃荷净 Oracle数据库中DBMS_STATS常用方法(收集oracle数据库.索引.表等信息) –收集Oracle数据库信息命令 EXEC DBMS_STATS.gather_database_ ...

  9. 8个球放入3个盒子方式_盒子这样做皮薄如纸,不露馅超好吃,孩子一口气吃好几个...

    煎饼盒子是我们爱吃的面点之一,做法有很多种,油炸.烙等.面也有烫面和发面之分,我们此次是用烫面和发面混合制成,不用单独和面,方法简单,口感酥软,十分钟就能搞定这道美食,简单方便又快手,大家可以尝试.盒 ...

最新文章

  1. mysql事件调度定时任务_详解MySQL用事件调度器Event Scheduler创建定时任务
  2. jQuery 第二章
  3. c# 连接mysql数据库_C#连接Mysql数据库
  4. 服务器虚拟主机划分,服务器划分虚拟主机教程
  5. html和css知识,html和 css基础知识
  6. 扎心!“就业难”背后的“十宗罪”我竟占了一半
  7. C#判断某天是否是周末或者节假日示例
  8. LeetCode 1072. 按列翻转得到最大值等行数(查找相同的模式,哈希计数)
  9. 网易云课堂解析_使用SQL分析网易云课堂职场提升类课程
  10. 8 SD配置-企业结构-分配-给公司代码分配销售组织
  11. NLP--Word2Vec详解
  12. LeetCode: Minimum Time Difference
  13. matlab 附录 周开利,【新书推荐】【2005.07】神经网络模型及其MATLAB仿真程序设计(周开利)...
  14. 查看你的姓氏排名和姓氏来源
  15. 华为AX3路由器获取ipv6外网地址方式
  16. linux内核鼠标配置,linux开启鼠标驱动和qt鼠标支持
  17. 飞信2010分析 – SIPC验证
  18. 喧喧发布 2.5.4 版本,新增客户端界面缩放等功能
  19. 微软Project项目管理软件简介
  20. 透过“500家门店计划”,看华为的“全屋智能”野心

热门文章

  1. php 转换成字节数组吗,在PHP中如何将字节数组转换成字符串?
  2. 程序猿开发软件插件推荐
  3. Ubunt下使用Alsa以及Alsa和PulseAudio
  4. Python实现自动古诗文查询系统
  5. git创建及切换分支/重置账户
  6. 【Excel函数】计算指定单元格内的指定字符数量——COUNTIF()
  7. mysql 最大连接池数_mysql 最大连接数 连接池
  8. 面向对象技术在开放式数控中的应用
  9. 【杂谈】关于断点调试Lua二三事(金X)
  10. matlab中线条4px,matlab 地图散点图