Oracle批量恢復drop操做刪除的表、索引等對象

/**********************************************************************
查詢Drop操做刪除的對象select * from recyclebin ;
單個對象(表、索引或是經過drop操做刪除的其它對象)恢復
flashback table(被刪除的對象類型) 被刪除的對象名稱 to before drop
***********************************************************************/
--Demo單張表恢復
flashback table Table_XXX to before drop;
-- 建立批量恢復表的存儲過程
create or replace procedure RecoveryOfTable is
begin
declare
/***********************************************************************
select 'flashback table '||a.original_name||' to before drop' from
recyclebin a where a.operation = 'DROP' and a.type='TABLE'
恢復其它類型對象請將flashback table 這裏換爲其它類型,
type='相應的類型'可加更多條件限制,具體查詢recyclebin
***********************************************************************/
cursor cur_flashback is select 'flashback table '||a.original_name||' to before drop' from
recyclebin a where a.operation = 'DROP' and a.type='TABLE';
v_name varchar2(4000);
begin
open cur_flashback;
fetch cur_flashback into v_name;
while cur_flashback%found
loop
execute immediate v_name;
fetch cur_flashback into v_name;
end loop;
dbms_output.put_line('恢復成功!');
close cur_flashback;
end;
end;
--執行存儲過程(使用plsql操做時)
begin
RecoveryOfTable;
end;
--執行存儲過程(使用SQL調用)
execute RecoveryOfTable;sql

相關文章
相關標籤/搜索