ORCAL 临时创建表与删除表

2022-07-21,,,

一.orcal临时表分类

1.会话级临时表

  • 1).保存一个会话session的数据。
  • 2).当会话退出时,临时表数据自动清空。表结构与元数据还存储在用户数据字典。

总结:会话级临时表是指临时表中的数据只在会话生命周期之中存在,当用户退出会话结束的时候,oracle自动清除临时表中数据。

2.事务级临时表

  • 1).保存一个事务中需要的数据。
  • 2).当事务提交或则回滚的时候,临时表数据自动清空。表结构与元数据还存储在用户数据字典。

总结:事务级临时表是指临时表中的数据只在事务生命周期中存在,当事务提交或则回滚的时候,oracle自动清除临时表中数据。

二.临时表创建

1.会话级临时表

1).先创建后插入数据

create global temporary table table_name (col1 type1,col2 type2...) on commit preserve rows;

  insert into table_name values("","");

2).创建时直接插入数据

create global temporary table table_name on commit preserve rows as select col1, col2 from query_table_name where...;


2.事务级临时表

1).先创建后插入数据

create global temporary table table_name (col1 type1,col2 type2...) on commit delete rows;

  insert into table_name values("","");

2).创建时直接插入数据

create global temporary table table_name on commit delete rows as select col1, col2 from query_table_name where...;

三.删除临时表

如果创建临时表的会话没有结束,则无法删除临时表,因为临时表还在使用之中。但是结束会话(关闭创建会话级临时表的命令窗口)后就可以删除了;

drop table table_name;

四.删除时报错

描述:关闭原先的命令窗口,然后执行 drop table table_name;
报错:ora-14452:试图创建,更改或删除正在使用的临时表中的索引

1.清空表,然后删除表

truncate table test_table;
drop table test_table;

2.杀掉进程,然后删除

select sid, serial# from v$session
where sid = (select sid from v$lock
where id1 = (select object_id  from user_objects
where object_name = upper('test_table')));

如果无权限则执行授权

grant select any dictionary to user;
查询到该session的sid和serial#:

然后杀掉进程:

lter system kill session 'sid,serial#';

最后进行删除

drop table test_table;

到此这篇关于orcal 临时创建表与删除表的文章就介绍到这了,更多相关orcal 表创建与删除内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!

《ORCAL 临时创建表与删除表.doc》

下载本文的Word格式文档,以方便收藏与打印。