1,创建临时表
SQL> CREATE GLOBAL TEMPORARY TABLE "HR"."TEMP_TABLE" ( "X" VARCHAR2(10)) ON COMMIT PRESERVE ROWS;
Table created.
SQL> insert into temp_table select * from test;
5 rows created.
SQL> select * from temp_table;
X
----------
1
2
3
4
5
SQL> commit;
Commit complete.
SQL> select * from temp_table;
X
----------
1
2
3
4
5
SQL> conn soe/soe;
Connected.
SQL> conn hr/oracle
Connected.
SQL> select * from temp_table;
no rows selected
总结:可见会话级级临时表只在当前会话中有效,当会话结束后表中数据被清空,表结构及元数据依然存在用户的数据字典中。
SQL> insert into temp_table select * from test;
5 rows created.
SQL> select * from temp_table;
X
----------
1
2
3
4
5
SQL> commit;
Commit complete.
现在另重新打开一个session,然后查询该临时表。
SQL> select * from temp_table;
no rows selected
在新开的会话中重新插入数据:
SQL> select * from temp_table;
X
----------
6
7
8
9
SQL> commit;
Commit complete.
现在在原会话中查看该临时表
SQL> select * from temp_table;
X
----------
1
2
3
4
5
依然没有变化
总结:临时表中的数据只对当前session有效,每个session都有自己的临时数据并且不能访问其他session的临时表中的数据。