Home > Database > Mysql Tutorial > body text

Oracle 数据库中 drop table 与purge

WBOY
Release: 2016-06-07 17:12:34
Original
1569 people have browsed it

实际示例: 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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template