By default when a table is dropped oracle does not immediately remove the space, but renames it and places the table and associated objects in recycle bin which allows it to be recovered at a later time. The recycle bin is a data dictionary table that contains info needed to recover dropped tables. Original table stays in place and occupies same space until purged or database needs space for storage. Tablespaces are not placed in recycle bin and once dropped are gone. All tables in that tablespace are removed from recycle bin if they have previously been dropped. Recycle bin can be disabled with recyclebin initialization parameter. To recover a dropped table from the recyclebin the command ‘FLASHBACK TABLE …. TO BEFORE DROP; ‘is used. You must use the system generated recyclebin name. You can rename the table with RENAME clause during recovery. The USER_RECYCLEBIN view can be used to find the system generated recyclebin name. This article demonstrates the use of flashback table.
- Logon to SQLPLUS as the user scott.
[oracle@linux2 ~]$ scott/password
SQL*Plus: Release 12.1.0.2.0 Production on Fri Jan 6 08:25:35 2016
Copyright (c) 1982, 2014, Oracle. All rights reserved.
Connected to:
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 – 64bit Production
With the Partitioning, OLAP, Advanced Analytics, Real Application Testing
and Unified Auditing options
SQL>
- Create table fb_test.
create table fb_test(fname varchar2(30), amt number);
SQL> create table fb_test(fname varchar2(30), amt number);
Table created.
SQL>
- Perform insert into test table fb_test and commit;
insert into scott.fb_test(fname,amt) values(‘Larry’,111);
commit;
SQL> insert into scott.fb_test(fname,amt) values(‘Larry’,111);
commit;
1 row created.
SQL>
Commit complete.
SQL>
- Select the values from test table fb_test.
SQL> select * from fb_test;
FNAME AMT
—————————— ———-
Larry 111
SQL>
- Drop the test table fb_test.
SQL> drop table fb_test;
Table dropped.
SQL>
- Attempt a select from table fb_test and see the table does not exist.
SQL> select * from fb_test;
select * from fb_test
*
ERROR at line 1:
ORA-00942: table or view does not exist
SQL>
- Flashback the dropped table.
SQL> flashback table fb_test to before drop;
Flashback complete.
SQL>
- Perform select operation on table fb_test.
SQL> select * from fb_test;
FNAME AMT
—————————— ———-
Larry 111
SQL>
- This completes flashback to table.
Larry Catt
OCP