Oracle retore table from recyclebin using flashback table

Find table type in recyclebin

select * from dba_recyclebin 
where owner = 'USERNAME' and type like '%TABLE%' and droptime > '2023-11-06:06:00:00' 
order by original_name desc;

flashback table command

FLASHBACK TABLE owner.original_name TO BEFORE DROP;

generate flashback table using PL/SQL

set serveroutput on;
begin
  for rec in (select 'FLASHBACK TABLE '||owner||'.'||original_name||' TO BEFORE DROP' as command
              from dba_recyclebin where owner = 'USERNAME' and type like '%TABLE%' and droptime > '2023-11-06:06:00:00'
              order by original_name desc)
  loop
    begin
      execute immediate rec.command;
    exception when others then
      dbms_output.put_line(sqlerrm || ' ' || rec.command);
    end;
  end loop;
end;
/

Note:

1. Flashback tables containing both indexes and status are valid.

2. The recovery index name is the name of the recyclebin and can be renamed after the flashback is finished.

張貼留言

0 留言