Oracle 临时表 (Gobal Temporary Table)

article/2025/9/21 14:06:25

提问,插入数据之后,COMMIT,数据是否一定会在表里呢?

回答 一定会在。我认为没有错

回答 可能会在。也没有错  → 没在就一定是被删了,那么有一种表,会在Commit时,清空所有数据。


刚才说的那种就是Gobal Temporary Table,临时表。

当然人为定义创建规定当然也可以,各有好处,自己判断。

ON COMMIT DELETE ROWS;   →在COMMIT的时候,删除所有数据

如果没有COMMIT,数据会不会留下来呢?Oracle想到了,临时表中的数据可以在session中断时被自动drop,如当用户退出或者Session异常中断. 

以下为转载内容:

From:http://hwhuang.iteye.com/blog/551864

From:http://www.oracle-base.com/articles/8i/TemporaryTables.php 
Applications often use some form of temporary data store for processes that are to complicated to complete in a single pass. Often, these temporary stores are defined as database tables or PL/SQL tables. In Oracle 8i, the maintenance and management of temporary tables can be delegated to the server by using Global Temporary Tables. 
=>应用者经常需要用临时数据组成的一些表,store一些用单一的方式很难达到的过程。通常,这些临时性stores被定义为数据库表或pl/sql 表。在oracle 8i,临时表的维护和管理通过用全局临时表来委派给server.

Creation of Global Temporary Tables 
The data in a global temporary table is private, such that data inserted by a session can only be accessed by that session. The session-specific rows in a global temporary table can be preserved for the whole session, or just for the current transaction. The ON COMMIT DELETE ROWS clause indicates that the data should be deleted at the end of the transaction.
 
=>创建全局临时表 
在全局临时表中的数据是私有的,在一个session中插入的数据只能在同一个session中被获取。在全局临时表中指定session里的行被保存在整个session或者是当前的transaction中。on commit delete rows语句说明在session中的数据应该在transaction结束时被delete.例如: 

Java代码   收藏代码
  1. CREATE GLOBAL TEMPORARY TABLE my_temp_table (  
  2.   column1  NUMBER,  
  3.   column2  NUMBER  
  4. ) ON COMMIT DELETE ROWS;  

In contrast, the ON COMMIT PRESERVE ROWS clause indicates that rows should be preserved until the end of the session. 
=>相反,on commit preserve rows 语句指出直至session结束data应该保存在内存中。  
Java代码   收藏代码
  1. CREATE GLOBAL TEMPORARY TABLE my_temp_table (  
  2.   column1  NUMBER,  
  3.   column2  NUMBER  
  4. ) ON COMMIT PRESERVE ROWS;  

Miscellaneous Features 
If the TRUNCATE statement is issued against a temporary table, only the session specific data is trucated. There is no affect on the data of other sessions. 
=>如果truncate一个临时表时,只是对当前session里的数据trucate,而对其它session里的数据没有任何影响。  
Data in temporary tables is automatically delete at the end of the database session, even if it ends abnormally. 
=>即使session以不正常结束,临时表中的数据也会在session结束时候被自动删除。  
Indexes can be created on temporary tables. The content of the index and the scope of the index is that same as the database session. 
Views can be created against temporary tables and combinations of temporary and permanent tables. 
=>index能被创建在临时表上,索引的内容和范围与session的一样。view能被创建在临时表,以及临时表与永久表的结合表上。(这里所谓结合表,应该是联合查询取得的数据表)  
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锁对于临时表的数据来说没有影响,因为每个Session都有它私有的数据。  
Temporary tables can have triggers associated with them. 
Export and Import utilities can be used to transfer the table definitions, but no data rows are processed. 
=>临时表有trigger与之关联。导入,导出功能也可以放在表定义的转换,但是没有数据。  

Specify GLOBAL TEMPORARY to indicate that the table is temporary and that its definition is visible to all sessions. The data in a temporary table is visible only to the session that inserts the data into the table. 
特定全局临时表---对于所有的Session都可见,并且临时表中的数据只对插入数据到表中的Session可视。 
Restrictions: 
=>局限性:  
1.Temporary tables cannot be partitioned, index-organized, or clustered. 
=>临时表不能被分区,索引化和群集。  
2.You cannot specify any referential integrity (foreign key) constraints on temporary tables. 
=>不能在临时表上指定任何完整性约束。  
3.Temporary tables cannot contain columns of nested table or varray type. 
=>临时表中不能包含嵌套表或变量数组之类的列。  
4.You cannot specify the following clauses of the LOB_storage_clause: TABLESPACE, storage_clause, LOGGING or NOLOGGING, MONITORING or NOMONITORING, or LOB_index_clause. 
=>不能指定如下clause:TABLESPACE, storage_clause, LOGGING or NOLOGGING, MONITORING or NOMONITORING, or LOB_index_clause.  
Parallel DML and parallel queries are not supported for temporary tables. (Parallel hints are ignored. Specification of the parallel_clause returns an error.) 
=>相应的DML和queries也不支持临时表。  
5.You cannot specify the segment_attributes_clause, nested_table_storage_clause, or parallel_clause. 
=>同时在临时表上指定segment_attributes_clause, nested_table_storage_clause, or parallel_clause。 6.Distributed transactions are not supported for temporary tables. 
=>临时表也不支持分布式事务。 
以下是一个Global Temporary Table的实例:
 
Java代码   收藏代码
  1. create global temporary table T_FORM4_POL_CHG_TMP  
  2. (  
  3.   POLICY_ID     NUMBER(10) not null,  
  4.   CHANGE_ID     NUMBER(10),  
  5.   SERVICE_ID    NUMBER(10),  
  6.   FINISH_TIME   DATE,  
  7.   CASE_ID       NUMBER(10),  
  8.   WITHDRAW_TIME DATE,  
  9.   CHANGE_STATUS VARCHAR2(2)  
  10. );  

临时表的介绍: 
Data in a temporary table is private to the session. Each session can only see and modify its own data. 
=>在临时表中的数据只是对当前session可见,每个session仅能访问和修改属于它的数据。  
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 crash. 
=>对临时表的DML操作,不会对数据变化生成重做日志。然而,可以生成对数据的撤销日志和对撤销日志的重做日志。临时表中的数据可以在session中断时被自动drop,如当用户退出或者Session异常中断.  
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. 
=>你能在临时表上创建索引,在临时表上的索引也是临时的,在索引上的数据同临时表中的数据一样,在相同的session或事务中。同时,也能在临时表上创建视图和触发器。  

Segment Allocation 段的分配 
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. 
=>临时表用临时段。与永久表不同,临时表和属于它的索引在被创建时候,是无法自动分配段空间。取而代之,在第一次插入数据的时候,段空间才会被分配。换句话说,在Select,Update,delete执行前,必须做insert操作,因为那时数据表都为空。  
You can perform DDL statements (ALTER TABLE, DROP TABLE, CREATE INDEX, and so on) on a temporary table only when no session is currently bound to it. A session gets bound to a temporary table when an INSERT is performed on it. The session gets unbound by a TRUNCATE, at session termination, or by doing a COMMIT or ABORT for a transaction-specific temporary table. 
=>仅当临时表不与临时表关联时候,才可以对它之行DDL操作(ALTER TABLE,DROP TABLE,CREATE INDEX等操作)。  
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. 
=>在Session结束或者Transaction结束时候临时段才会被收回。



http://chatgpt.dhexx.cn/article/QiEYf573.shtml

相关文章

转载:关于Vivado综合选项——Out of context per IP和Gobal

转载:关于Vivado综合选项——Out of context per IP和Gobal 原文地址:https://www.cnblogs.com/yhsy1002/p/7441309.html 关于Vivado综合选项——Out of context per IP和Gobal Vivado生成IP输出文件注意的地方,是选择Global还是Out of cont…

An Implemention of Realtime Gobal Illumination

前言:CG画面的“效果”最重要,至于达到这一效果所使用的技术倒是其次,一切的一切对于观众来说都是透明的。即使是Pixar都认为仅仅One Bounce Indirect Illumination对构建一个足够真实可信的光照效果足矣。看过这里的SII,我想你对…

Oracle ORA-06502 ORA-06512

问题描述&#xff1a; 发现存储过程里有对oracle <Collection>类型的操作 sql_text : select a.* from t_Drivewaystatus a inner join t_intersection b on a.intersectioncode b.intersectioncode where b.used 1 order by a.intersectioncode,a.drivewaycode; open…

ora-20011 ora-01555

问题 解决方案 ora undoinfo alter tablespace undotbs1 add datafile size 30g; alter tablespace undotbs2 add datafile size 30g; ora undoinfoora tempfree alter tablespace temp add tempfile size 30g; ora tempfree

ora-01461

插入数据长度大于4000&#xff0c;报该错ora-01461 解决方式&#xff1a;修改字段类型为 clob&#xff0c; 第一步&#xff1a;添加一个clob类型字段 ALTER TABLE tb_a ADD (RYZP CLOB);第二步&#xff1a;删除原来的字段 ALTER TABLE tb_a DROP COLUMN RYZP1;上面只是我工…

ORA-01156

需要关闭mrp进行操作。 alter database recover managed standby database cancel; alter database recover managed standby database parallel 10 using current logfile disconnect from session;

拼接字符串报错:Oracle: ORA-06512:字符串缓冲区太小

报错目前可以肯定的是&#xff0c;拼接的字符串超过oracle定义的上限。 plsql中varchar2长度上限是4000字节 报错语句定位到下面的这句&#xff1a; 我这里的p_zbdcdyh是存储过程的输出参数&#xff0c;故是默认数据库的字符串varchar2的大小。 p_zbdcdyh:p_zbdcdyh||,||PSELEN…

图像传感器设计资料-764-GSPRINT4502 2MP-4.5微米 全局快门 高速 CMOS 图像传感器

GSPRINT4502 2MP-4.5微米 全局快门 高速 CMOS 图像传感器 GSPRINT4502是一款一千万分辨率 (2048 x 1216) &#xff0c;2/3”光学尺寸的高速图像传感器&#xff0c;采用最新的4.5微米电荷域全局快门像素设计&#xff0c;实现30ke-的满阱容量和小于4e-的读出噪声。利用先进的65n…

转:详细图解,一眼就能看懂!卷帘快门(Rolling Shutter)与全局快门(Global Shutter)的区别

什么是快门 快门是照相机用来控制感光片有效曝光时间的机构。是照相机的一个重要组成部分&#xff0c;它的结构、形式及功能是衡量照相机档次的一个重要因素。 什么是Global Shutter&#xff08;Total Shutter&#xff09;&#xff1f; 通过整幅场景在同一时间曝光实现的。Sen…

详细图解,一眼就能看懂!卷帘快门(Rolling Shutter)与全局快门(Global Shutter)的区别

什么是快门 快门是照相机用来控制感光片有效曝光时间的机构。是照相机的一个重要组成部分&#xff0c;它的结构、形式及功能是衡量照相机档次的一个重要因素。 什么是Global Shutter&#xff08;Total Shutter&#xff09;&#xff1f; 通过整幅场景在同一时间曝光实现的。S…

VIO与全局快门及轮速计的一些应用小技巧

封面就用一个可爱的小车车~ 之前各种针对VIO&#xff0c;VSLAM和VINS的工程注意事项都讲过了 今天的内容主要是针对VSLAM&#xff0c;VIO的实用性。 比如Td&#xff0c;同步对时&#xff0c;内参&#xff0c;外参这一串 最近比较忙&#xff0c;简单写点全局快门和轮速计的东…

图解:卷帘快门(Rolling shutter)与全局快门(global shutter)的区别

什么是快门 快门是照相机用来控制感光片有效曝光时间的机构。是照相机的一个重要组成部分&#xff0c;它的结构、形式及功能是衡量照相机档次的一个重要因素。 什么是Global Shutter&#xff08;Total Shutter&#xff09;&#xff1f; 通过整幅场景在同一时间曝光实现的。Sens…

卷帘快门(Rolling Shutter)与全局快门(Global Shutter)的区别

转载的原始连接&#xff1a; https://blog.csdn.net/abcwoabcwo/article/details/93099982 快门是照相机用来控制感光片有效曝光时间的机构。是照相机的一个重要组成部分&#xff0c;它的结构、形式及功能是衡量照相机档次的一个重要因素。 什么是Global Shutter&#xff08;…

安森美的全局快门图像传感器解决机器视觉的成像需求

在“工业4.0”和“中国制造2025”的大势下&#xff0c;工业自动化趋势持续增强&#xff0c;机器视觉成为电子行业重要的新兴领域。在持续的自动化需求、社会安全保障需求和市场经济实力的推动下&#xff0c;全球机器视觉和智能交通系统市场迎来发展热潮。在中国&#xff0c;越来…

763-GMAX3809 1.1” 900万分辨率全局快门CMOS图像传感器

GMAX3809 1.1” 900万分辨率全局快门CMOS图像传感器 GMAX3809采用3.8μm像素设计&#xff0c;光学尺寸为1.1”&#xff0c;分辨率为900万&#xff0c;12bit数据输出最快帧频65fps。 GMAX3809采用了3.8μm的大像素设计&#xff0c;有效分辨率为4096(H) x 2160(V) (…

全局快门和卷帘快门(Global shutter and Rolling shutter)

全局快门和卷帘快门 “果冻效应”是什么&#xff1f;用相机拍下扇叶&#xff0c;为什么会发生扭曲变形&#xff1f; 相机两种曝光方式的优劣&#xff1a;全局曝光和卷帘曝光 卷帘快门和全局快门的区别 全局曝光和卷帘曝光是常见的相机曝光方式 一般来说&#xff0c;CCD相机是全…

工业相机快门类型:卷帘快门和全局快门——哪个最好?

CMOS 成像传感器是每个工业相机系统的核心&#xff0c;但它们有两种快门方式——卷帘快门或全局快门。每种类型的快门都有其优点&#xff0c;但哪一种最好&#xff1f;这取决于具体的应用程序。所以&#xff0c;让我们来看看它们之间的差异&#xff0c;以帮助您决定哪一个最适合…

图解:卷帘快门(Rolling_shutter)与全局快门(global_shutter)的区别

[toc](卷帘快门(Rolling shutter)与全局快门(global shutter)的区别) 卷帘快门(Rolling shutter)与全局快门(global shutter)的区别 快门是照相机用来控制感光片有效曝光时间的机构。是照相机的一个重要组成部分&#xff0c;它的结构、形式及功能是衡量照相机档次的一个重要因…

卷帘快门与全局快门的区别

卷帘快门与全局快门 卷帘快门&#xff0c;通常用于CMOS传感器。使用这种快门&#xff0c;传感器在曝光时并不是所有像素同时感光的&#xff0c;而是每行像素按照顺序依次感光。 全局快门的工作方式就像我们通常想象的那样&#xff0c;所有像素同时感光&#xff0c;在任意一个…

卷帘快门和全局快门的区别

技术背景 多面检测和图像处理任务需要足够的由光学、摄像机和PC机组成的图像采集系统&#xff0c;每个部件的特征对任务的完成有着重要的影响。在相机方面&#xff0c;你可能首先想到的是分辨率&#xff0c;帧速率和PC数据传输接口。 但是&#xff0c;在选择相机时必须考虑一…