GLOBAL TEMPORARY TABLE(轉)
在Oracle中,可以建立以下兩種臨時表:
1) 會話特有的臨時表
CREATE GLOBAL TEMPORARY ( )
ON COMMIT PRESERVE ROWS;
2) 事務特有的臨時表
CREATE GLOBAL TEMPORARY ( )
ON COMMIT DELETE ROWS;
CREATE GLOBAL TEMPORARY TABLE MyTempTable
所建的臨時表雖然是存在的,但是如果insert 一條記錄然後用別的連線登上去select,記錄是空的。
--ON COMMIT DELETE ROWS 說明臨時表是事務指定,每次提交後ORACLE將截斷表(刪除全部行)
--ON COMMIT PRESERVE ROWS 說明臨時表是會話指定,當中斷會話時ORACLE將截斷表。
2 動態建立
create or replace procedure pro_temp(v_col1 varchar2,v_col2 varchar2) as
v_num number;
begin
select count(*) into v_num from user_tables where table_name='T_TEMP';
--create temporary table
if v_num<1 then
execute immediate 'CREATE GLOBAL TEMPORARY TABLE T_TEMP (
COL1 VARCHAR2(10),
COL2 VARCHAR2(10)
) ON COMMIT delete ROWS';
end if;
--insert data
execute immediate 'insert into t_temp values(''' v_col1 ''',''' v_col2 ''')';
execute immediate 'select col1 from t_temp' into v_num;
dbms_output.put_line(v_num);
execute immediate 'delete from t_temp';
commit;
execute immediate 'drop table t_temp';
end pro_temp;
測試:
15:23:54 SQL> set serveroutput on
15:24:01 SQL> exec pro_temp('11','22');
11
PL/SQL 過程已成功完成。
已用時間: 00: 00: 00.79
15:24:08 SQL> desc t_temp;
ERROR:
ORA-04043: 物件 t_temp 不存在
3 特性和效能(與普通表和檢視的比較)
臨時表只在當前連線內有效
臨時表不建立索引,所以如果資料量比較大或進行多次查詢時,不推薦使用
資料處理比較複雜的時候時錶快,反之檢視快點
在僅僅查詢資料的時候建議用遊標: open cursor for 'sql clause';
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/756652/viewspace-242157/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- [20230227][20230109]Oracle Global Temporary Table ORA-01555 and Undo Retention.tOracle
- [20200819]12c Global Temporary table 統計資訊的收集的疑問.txt
- oracle cache table(轉)Oracle
- Oracle Pipelined Table(轉)Oracle
- Oracle Pipelined Table Functions(轉)OracleFunction
- [virtualbox] temporary failure in name resolutionAI
- Fiori Elements List Report table 裡的普通按鈕,Global 按鈕 和 Determining 按鈕
- layui將table轉化表單顯示(即table.render轉為表單展示)UI
- SCSS !globalCSS
- Temporary failure resolving ‘archive.ubuntu.com‘AIHiveUbuntu
- flink stream轉table POJO物件遇到的坑POJO物件
- [20220610][轉載]Is my table marked for archive.txtHive
- sap table 分為三種型別(轉)型別
- 利用poi將Html中table轉為ExcelHTMLExcel
- Deep Global Registration
- 4.4global
- JavaScript Global 物件JavaScript物件
- temporary、interim、tentative和provisional的區別
- ftp_rawlist: Unable to create temporary file.FTP
- Sybase IQ 錯誤 : Temporary space limit exceededMIT
- Resolving archive.cloudera.com... failed: Temporary failure in nameHiveCloudAI
- Codeforces Global Round 27
- Codeforces Global Round 26
- Codeforces Global Round 13
- @@GLOBAL.GTID_PURGED can only be set when @@GLOBAL.GTID_EXECUTED is empty
- create table,show tables,describe table,DROP TABLE,ALTER TABLE ,怎麼使用?
- [20181112]Private Temporary Tables Oracle Database 18C.txtOracleDatabase
- [Vue] Provide and Inject Global StorageVueIDE
- Codeforces Global Round 26 (A - D)
- Python GIL(Global Interpreter Lock)Python
- 【MySQL】ERROR 1878 (HY000): Temporary file write failure.MySqlErrorAI
- TableTools Export Excel前Table內容格式的轉換應用ExportExcel
- table
- vim之強大的global
- Synced Global AI Weekly | 2018.10.20—10.26AI
- Synced Global AI Weekly | 2018.10.6—10.12AI
- Synced Global AI Weekly | 2018.10.27—11.2AI
- NodeJS require a global module/package in linuxNodeJSUIPackageLinux