本文共 1797 字,大约阅读时间需要 5 分钟。
临时表在日常工作中可能使用比较多,但是大家都对临时表相关的一些知识了解比较少。我们来简单说数理一下。
SQL> select tablespace_name,logging from dba_tablespaces;
TABLESPACE_NAME LOGGINGTEMPTS1 NOLOGGING
8 rows selected.
TABLESPACE_NAME FILE_NAME
13 rows selected.
SQL> select file_name,tablespace_name ,bytes,status from dba_temp_files;
FILE_NAME TABLESPACE_NAME BYTES STATUS13788 100% /u03
SQL> create temporary tablespace tempts2 tempfile '/u03/ora11g/oradata/TEST01/temp02.dbf' size 10M;
Tablespace created.
SQL> !df -k|grep u0312752 100% /u03
但是奇怪的是查看临时文件的大小,却是实实在在的10M.
SQL> create temporary tablespace tempts2 tempfile '/u03/ora11g/oradata/TEST01/temp02.dbf' size 10M;
Tablespace created.
no rows selected
我们可以简单的使用alter tablespace语句把临时表空间放入对应的组中。
Tablespace altered.
SQL> alter tablespace tempts1 tablespace group temp;
Tablespace altered.
查看临时表空间组的情况
GROUP_NAME TABLESPACE_NAME
SQL> alter tablespace tempts2 tablespace group '';
Tablespace altered.
SQL> select * from dba_tablespace_groups;
GROUP_NAME TABLESPACE_NAME
SQL> create global temporary table temp_session on commit preserve rows as select *from user_tables where rownum<5;
Table created.
SQL> create global temporary table temp_transaction on commit delete rows as select *from user_tables where rownum<5;
Table created.
temp_session是基于会话级别的,在同一个会话中,提交之后数据还是存在,除非指定了delete或者truncate操作,而temp_transaction是基于事务层面的,在commit的时候就会自动清空数据。
SQL> select count(*)from temp_session;
COUNT(*)
SQL> select count(*)from temp_transaction;
COUNT(*)
我们尝试删除temp_session中的数据。
SQL> delete from temp_session;
4 rows deleted.
SQL> select count(*)from temp_session;
COUNT(*)
SQL> rollback;
Rollback complete.
SQL> select count(*)from temp_session;
COUNT(*)
断开连接
COUNT(*)
SQL> select count(*)from temp_transaction;
COUNT(*)
临时表的使用还是比较广泛的,而且临时表中的数据都是对当前session可见,有session级和事务级的生命周期,不存在并发的困扰。合理的使用还是能够发挥很好的效果。
转载地址:https://jeanron100.blog.csdn.net/article/details/102507010 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!