临时表分为SESSION、TRANSACTION两种,SESSION级的临时表数据在整个SESSION都存在,直到结束此次SESSION;而TRANSACTION级的临时表数据在TRANACTION结束后消失,即COMMIT/ROLLBACK或结束SESSION都会清除TRANACTION临时表数据。默认为transaction级
测试:
1.
SQL> create global temporary table t_temp (id int,name varchar2(2));
表已创建。
2.
SQL> insert into t_temp VALUES(1,'A');
已创建 1 行。
SQL> select * from t_temp;
ID NA
---------- --
1 A
SQL> commit;
提交完成。
SQL> select * from t_temp; --提交完后看不到数据
未选定行
二、session级临时表
SQL> create global temporary table t_temp(id int,name varchar2(10))
2 on commit preserve rows;
表已创建。
插入数据
SQL> insert into t_temp values(1,'A');
已创建 1 行。
SQL> select * from t_temp;
ID NAME
---------- ----------
1 A
SQL> commit;
提交完成。
SQL> select * from t_temp; --提交后还能查到数据
ID NAME
---------- ----------
1 A
退出会话后,数据消失
在临时表上可以创建索引
测试:
1.
SQL> create global temporary table t_temp (id int,name varchar2(2));
表已创建。
2.
SQL> insert into t_temp VALUES(1,'A');
已创建 1 行。
SQL> select * from t_temp;
ID NA
---------- --
1 A
SQL> commit;
提交完成。
SQL> select * from t_temp; --提交完后看不到数据
未选定行
二、session级临时表
SQL> create global temporary table t_temp(id int,name varchar2(10))
2 on commit preserve rows;
表已创建。
插入数据
SQL> insert into t_temp values(1,'A');
已创建 1 行。
SQL> select * from t_temp;
ID NAME
---------- ----------
1 A
SQL> commit;
提交完成。
SQL> select * from t_temp; --提交后还能查到数据
ID NAME
---------- ----------
1 A
退出会话后,数据消失
在临时表上可以创建索引
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/26937943/viewspace-1236746/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/26937943/viewspace-1236746/