动态网站制作指南 [  QQ表情  ]
[ 投票调查 ]
[ 企业邮箱 ]
[ 网站空间 ]
网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
ASP源码 | .Net源码 | PHP源码 | JSP源码 | JAVA源码 | CGI源码 | VB源码 | C++源码 | Delphi源码 | PB源码 | VF源码 | 汇编 | 服务器
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > 数据库 > Oracle教程
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
数据库:数据库教程,数据库技巧,Oracle教程,MySQL教程,Sybase教程,Access教程,DB2教程,数据库安全,数据库文摘
文章搜索服务
邮件订阅
输入你的邮件地址,
你将不会错过任何关于:
[ Oracle教程 ]的信息

本月文章推荐
.删除一个Oracle用户的对象.
.eval用法三例.
.数据库人员手册之Oracle初始化参.
.Oracle listener静态注册和动态注.
.linux下安装oracle9i.
.TNS-12500,TNS-12540,TNS-1256.
.如何在Oracle里用存储过程定期分.
.proftpd faq.
.SSH进阶(二):FTP转发.
.Oracle中Trigger例子1.
.ORACLE数据库备份实用方案.
.Oracle9i中监视索引的使用(1).
.如何选购Linux可以搭配的机器之B.
.IDC:Oracle数据库依然是首选.
.ORACLE 9.2.0.4 PATCHES 安装!.
.国人的一些错误观念.
.Oracle中的用户管理的不完全恢复.
.如何查看正在运行的过程?.
.全球获得Oracle认证人数最新统计.
.Qmail如何通过UUCP进行邮件外发.

临时表更适合做插入和查询操作

发表日期:2008-2-9 |



  Oracle数据库除了可以保存永久表外,还可以建立临时表temporary tables。这些临时表用来保存一个会话SESSION的数据,或者保存在一个事务中需要的数据。 当会话退出或者用户提交commit和回滚rollback事务的时候,临时表的数据自动清空(truncate),但是临时表的结构以及元数据还存储在用户的数据字典中。
  
  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 for the duration of a transaction or session.
  
  Temporary tables are supported by Oracle9i and Oracle8i.
  
  2具体介绍
  
  Oracle临时表分为 会话级临时表 和 事务级临时表。
  
  会话级临时表是指临时表中的数据只在会话生命周期之中存在,当用户退出会话结束的时候,Oracle自动清除临时表中数据。
  
  事务级临时表是指临时表中的数据只在事务生命周期中存在。当一个事务结束(commit or rollback),Oracle自动清除临时表中数据。
  
  临时表中的数据只对当前Session有效,每个Session都有自己的临时数据,并且不能访问其它Session的临时表中的数据。因此,临时表不需要DML锁。
  
  The CREATE GLOBAL TEMPORARY TABLE statement creates a temporary table that can be transaction-specific or session-specific. For transaction-specific temporary tables, data exists for the duration of the transaction. For session-specific temporary tables, data exists for the 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 other sessions that are using the same table.
  
  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. Data from the temporary table is automatically dropped in the case of session termination, either when the user logs off or when the session terminates abnormally sUCh as during a session or instance failure.
  
  你可以索引临时表和在临时表基础上建立视图.同样,建立在临时表上的索引也是临时的,也是只对当前会话或者事务有效.  临时表可以拥有触发器.
  
  You can create indexes for temporary tables using the CREATE INDEX statement. Indexes created on temporary tables are also temporary, and the data in the index has the same session or transaction 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 first INSERT (or CREATE TABLE AS SELECT) is performed. This means that if a SELECT, UPDATE, or DELETE is performed before the first INSERT, 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 的站点http://www.eygle.com/faq/temp_table.htm
  
  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,
  
  3      enddate DATE,
  
  4      class CHAR(20))
  
  5    ON 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,
  
  3      enddate DATE,
  
  4      class CHAR(20))
  
  5    ON 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;
  
  STARTDATE ENDDATE  CLASS
  
  17-1?? -03 17-1?? -03 session temperary
  
  会话2:
  
  SQL> select * from permernate;
  
  A
  
  1
  
  2
  
  SQL> select * from admin_work_area;
  
  未选择行.
  
  会话2看不见会话1中临时表的数据.
  
  temporary tables -- but they have to support
  
  a) read consistency
  b) rollback
  c) rollback to savepointhttp://asktom.oracle.com/pls/ask/f?p=4950:8:8284619847966507619::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:30774214640787
  
  they definitely -- totally definitely -- generate UNDO.
  
  consider:
  
  ops$tkyte@ORA9IUTF> create global temporary table t ( x int ) on commit preserve
  rows;
  Table created.
  ops$tkyte@ORA9IUTF> insert into t values ( 1 );
  1 row created.
  ops$tkyte@ORA9IUTF> variable x refcursor
  ops$tkyte@ORA9IUTF> exec open :x for select * from t;
  PL/SQL procedure successfully completed.
  
  that is (as always) a read consitent result set, it is pre-ordained, we
  haven't fetched a single row of data yet -- NO IO HAS BEEN performed, the result
  set is not 'copied' somewhere -- just like any other query
  
  
  ops$tkyte@ORA9IUTF> savepoint foo;

  Savepoint created.
  ops$tkyte@ORA9IUTF> insert into t values ( 2 );
  1 row created.
  ops$tkyte@ORA9IUTF> select * from t;
  X
  ----------
  1
  2
  
  that shows we can see two rows -- but
  ops$tkyte@ORA9IUTF> print x
  X
  ----------
  1
  
  that query used UNDO to rol
上一篇:Logon Trigger Example 登陆例子 人气:462
下一篇:使用exp工具进行数据库备份及恢复 人气:747
浏览全部Oracle教程的内容 Dreamweaver插件下载 常用网页广告代码全集
  最新网站源码 最新软件下载
2008-8-28 LDV个人相册系统 v1.6.1
2008-8-28 讯时网站管理系统CMS v3.5
2008-8-28 迅易评选管理系统 v9.3
2008-8-28 OpenX(广告管理系统) v2.6.1 多国
2008-8-28 雨点单用户免费留言板 v2.0 Buil
2008-8-28 APJE私服发布系统 v2.1 ASP版
2008-8-28 酷维CMS企业网站程序 v1.0
2008-8-27 风讯dotNETCMS v1.0 SP3 SQL/ACC
2008-8-27 风讯dotNETCMS v1.0 SP3 源码
2008-8-23 Mini WinMount V0.4
2008-8-23 Vista优化大师3.11正式版
2008-8-23 Wine 1.13
2008-8-23 KlipFolio 5.0 Build 5899-80
2008-8-23 Windows Sysinternals Desktops
2008-8-23 OneTap Movies1.2破解版
2008-8-23 AnnotaterPDF阅读1.1.503 破解版
2008-8-23 SoundMeter分贝测量仪 v1.0汉化破
2008-8-23 iDrum音乐节拍1.0破解版
  发表评论
姓 名: 验证码:
内 容:
站长工具:网站收录查询 | Google PR查询 | ALEXA排名查询 | CSS在线编辑器 | 广告代码 | Html转换js | js/vbs加密 | md5加密 | 进制转换
实用工具:汉字翻译拼音 | 符号对照表 | 个税计算 | 经典小工具 | 汉字简繁转换 | 普通单位换算 | 公制单位换算 | 生辰老黄历 | 国内电话区号 国家代码与域名缩写 | 文字加密解密 | 健康查询 | 万年历 | 汉字横竖排版 | 手机号码查询 | 计算器 | ip搜索
业务联系 | 广告刊登 | 频道合作 | 投稿荐稿 | 联系方式 | 加入收藏 | RSS订阅
Copyright © 2000-2008 www.knowsky.com All rights reserved | 网络实名:动态网站制作指南 | 沪ICP备05001343号