本篇文章給大家?guī)?lái)了關(guān)于Oracle的相關(guān)知識(shí),其中主要介紹了關(guān)于臨時(shí)表的相關(guān)問(wèn)題,包括了事務(wù)級(jí)臨時(shí)表、會(huì)話級(jí)臨時(shí)表等等內(nèi)容,下面一起來(lái)看一下,希望對(duì)大家有幫助。
推薦教程:《Oracle視頻教程》
一、Oracle 臨時(shí)表
臨時(shí)表是一種特殊的表。當(dāng)我們需要對(duì)某一(也可以是多個(gè))表中的一批數(shù)據(jù)進(jìn)行反復(fù)的操作時(shí),通過(guò)對(duì)這批數(shù)據(jù)創(chuàng)建一個(gè)臨時(shí)表,可能會(huì)簡(jiǎn)化操作并且有可能提高效率!
基本語(yǔ)法:
create global temporary table 臨時(shí)表名(colum,colum,.......)on commit delete rows;on commit preserve rows;
說(shuō)明:
- on commit delete rows; 說(shuō)明數(shù)據(jù)行只有在當(dāng)前事務(wù)中可見(jiàn),也是默認(rèn)值,事務(wù)提交后數(shù)據(jù)行將消失;創(chuàng)建的是事務(wù)級(jí)臨時(shí)表。
- on commit preserve rows; 說(shuō)明數(shù)據(jù)行僅在當(dāng)前會(huì)話中可見(jiàn);創(chuàng)建的是會(huì)話級(jí)臨時(shí)表。
二、示例演示
2.1、事務(wù)級(jí)臨時(shí)表
-- 創(chuàng)建事務(wù)級(jí)臨時(shí)表 tmp_user 注:on commit delete rows 可省略create global temporary table tmp_user ( user_id varchar2(10), user_name varchar2(20)) on commit delete rows;
2.2、會(huì)話級(jí)臨時(shí)表
-- 創(chuàng)建會(huì)話級(jí)臨時(shí)表 tmp_user1create global temporary table tmp_user1 ( user_id varchar2(10), user_name varchar2(20))on commit preserve rows;
三、臨時(shí)表說(shuō)明
- 臨時(shí)表的數(shù)據(jù)是基于一個(gè)會(huì)話或一個(gè)事務(wù)的,其它的會(huì)話不能訪問(wèn)到。
-
臨時(shí)表可專用于事務(wù)處理,也可專用于會(huì)話。對(duì)于專用于事務(wù)處理的臨時(shí)表而言,數(shù)據(jù)存在于事務(wù)處理期間;對(duì)于專用于會(huì)話的臨時(shí)表而言,數(shù)據(jù)存在于會(huì)話期間。在這兩種情況下,會(huì)話插入的數(shù)據(jù)專用于會(huì)話。每個(gè)會(huì)話僅可查看和修改自己的數(shù)據(jù)。因此,臨時(shí)表的數(shù)據(jù)從不會(huì)獲得 DML 鎖
推薦教程:《Oracle視頻教程》