Search notes:

Oracle: Recycle bin

Objects that were moved to the recyclebin typically have names starting with 'BIN$'.

Simple example

Empty the recycle bin for this example:
purge recyclebin;  
Make sure the recycle bin functionality is enabled for this session:
alter session set recyclebin = on;
Create a table with an index (primary key) …
create table tq84_recyclebin_test (
   id  integer generated always as identity primary key,
   val number(6,2)
);
… and fill a few values:
insert into tq84_recyclebin_test (val) values (7.01);
insert into tq84_recyclebin_test (val) values (5.83);
insert into tq84_recyclebin_test (val) values (5.26);
 
commit;
Drop table:
drop table tq84_recyclebin_test;
Table is not actually dropped, but moved to the recycle bin:
select
   object_name,
   original_name,
   type,
   can_undrop,
   operation
from
   user_recyclebin;
Undrop the table:
flashback table tq84_recyclebin_test to before drop;
The recycle bin is empty again …
select count(*) from user_recyclebin;
… and the original table is restored:
select * from tq84_recyclebin_test;
Drop the table again, this time, use the purge clause so that the table does not go to the recycle bin again:
drop table tq84_recyclebin_test purge;

TODO

Show the content of the recycle bin in SQL, using the data dictionary:
select object_name, original_name, operation, droptime from recyclebin;
Github repository Oracle-Patterns, path: /DatabaseObjects/Tables/RecycleBin/show_recycle_bin_sql.sql
Show the content of the recycle bin in SQL*Plus:
show recyclebin
Github repository Oracle-Patterns, path: /DatabaseObjects/Tables/RecycleBin/show_recycle_bin_sqlplus.sql
Purge the recycle bin:
purge recyclebin;
Github repository Oracle-Patterns, path: /DatabaseObjects/Tables/RecycleBin/purge.sql

See also

dba_recyclebin

Index