Home  >  Article  >  Database  >  Oracle 数据库中 drop table 与purge

Oracle 数据库中 drop table 与purge

WBOY
WBOYOriginal
2016-06-07 17:12:341514browse

实际示例: CREATE OR REPLACE PROCEDURE pro_droptable IS cursor cur is select table_name from user_tables where tab

实际示例:

CREATE OR REPLACE PROCEDURE pro_droptable IS

  cursor cur is

    select table_name from user_tables where table_name like 'TEMPTABLE%';

  drop_sql     varchar2(1000);

  table_number number;

BEGIN

  SELECT COUNT(*) INTO table_number from USER_TABLES WHERE TABLE_NAME LIKE 'TEM%';

  for tbname in cur loop

    begin

      if table_number

        exit;

      end if;

      drop_sql := 'drop table ' || tbname.table_name || 'purge';

      execute immediate drop_sql;

      table_number := table_number - 1;

  

    end;

  end loop;

END pro_droptable;

解释:

drop后的表被放在回收站(user_recyclebin)里,而不是直接删除掉。这样,,回收站里的表信息就可以被恢复,或彻底清除。
1.通过查询回收站user_recyclebin获取被删除的表信息,然后使用语句
flashback table to before drop [rename to ];
将回收站里的表恢复为原名称或指定新名称,表中数据不会丢失。
若要彻底删除表,则使用语句:drop table purge;
2.清除回收站里的信息
清除指定表:purge table ;
清除当前用户的回收站:purge recyclebin;
清除所有用户的回收站:purge dba_recyclebin;


示例2:

CREATE OR REPLACE PROCEDURE pro_clean_recycle IS

--tmpVar NUMBER;

clean_recycle_sql varchar2(1000);

BEGIN

   --purge recyclebin;

   clean_recycle_sql :='purge recyclebin';

   execute immediate clean_recycle_sql;

END pro_clean_recycle;

更多Oracle相关信息见Oracle 专题页面 ?tid=12

linux

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn