This flashback query allows us to query a table at a point in the past. We can retrieve which we might have deleted by mistake in the past.
Make sure flashback is enabled:
SQL> select flashback_on from v$database; FLASHBACK_ON ------------------ YES
If flashback is not enabled Refer: How to enable flashback in oracle
Delete some data:
09:10:51 SQL> select count(*) from test; COUNT(*) ---------- 87298 09:13:11 SQL> delete from test; 87298 rows deleted. 09:13:36 SQL> commit; Commit complete. 09:13:39 SQL> select count(*) from test; COUNT(*) ---------- 0
Now use timestamp to_date to query the table in past(for particular time stamp)
09:15:53 SQL> select count(*) from test AS OF TIMESTAMP TO_DATE('29-AUG-2015 09:10:51','DD-MON-YYYY HH24:MI:SS'); COUNT(*) ---------- 87298
Restore the deleted data
09:18:16 SQL> insert into test select * from test AS OF TIMESTAMP TO_DATE('29-AUG-2015 09:10:51','DD-MON-YYYY HH24:MI:SS'); 87298 rows created. 09:19:38 SQL> commit; Commit complete.
We can see by using flashback query, we are able get the deleted data from the past.