- Using Flashback Query with AS-OF clause oracle restore the past data without performing Media recovery.
- Flashback feature will use Undo_data from undo_retention to restore the transactions from the undo tables-pace.
Note :- First enable archivelog mode in your database and then configure FRA.
>> Here i had done a Small Scenario to Understand Flashback-Query Easily <<
- Check the counts of the emp1 table.
15:25:32 SQL> select count(*) from emp1;
64 rows selected.
>> NOW DELETE SOME RECORDS <<
15:25:44 SQL> delete from emp1 where comm='250';
24 rows deleted.
15:26:05 SQL> select count(*) from emp1;
COUNT(*)
----------
40
15:26:15 SQL> commit;
Commit complete.
>> Here we will retrive Lost Rows Using As-of clause with Flashback Query <<
15:30:41 SQL> select * from sam.emp1 as of timestamp to_timestamp ('11-01-2017 15:25:43', 'DD-MM-YYYY HH24:MI:SS') where comm='250';
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- --------- ---------- ---------- ------------------------------------------------
4578 TURNER7 ENGR7 3021 25-APR-87 1000 250 7
9826 TURNER10 ENGR10 3365 28-APR-87 9000 250 10
4578 TURNER7 ENGR7 3021 25-APR-87 1000 250 7
9826 TURNER10 ENGR10 3365 28-APR-87 9000 250 10
4578 TURNER7 ENGR7 3021 25-APR-87 1000 250 7
9826 TURNER10 ENGR10 3365 28-APR-87 9000 250 10
4578 TURNER7 ENGR7 3021 25-APR-87 1000 250 7
9826 TURNER10 ENGR10 3365 28-APR-87 9000 250 10
4578 TURNER7 ENGR7 3021 25-APR-87 1000 250 7
9826 TURNER10 ENGR10 3365 28-APR-87 9000 250 10
4578 TURNER7 ENGR7 3021 25-APR-87 1000 250 7
9826 TURNER10 ENGR10 3365 28-APR-87 9000 250 10
4578 TURNER7 ENGR7 3021 25-APR-87 1000 250 7
9826 TURNER10 ENGR10 3365 28-APR-87 9000 250 10
4578 TURNER7 ENGR7 3021 25-APR-87 1000 250 7
9826 TURNER10 ENGR10 3365 28-APR-87 9000 250 10
4578 TURNER7 ENGR7 3021 25-APR-87 1000 250 7
4578 TURNER7 ENGR7 3021 25-APR-87 1000 250 7
4578 TURNER7 ENGR7 3021 25-APR-87 1000 250 7
4578 TURNER7 ENGR7 3021 25-APR-87 1000 250 7
4578 TURNER7 ENGR7 3021 25-APR-87 1000 250 7
4578 TURNER7 ENGR7 3021 25-APR-87 1000 250 7
4578 TURNER7 ENGR7 3021 25-APR-87 1000 250 7
4578 TURNER7 ENGR7 3021 25-APR-87 1000 250 7
24 rows selected.
>> Now we will restore Lost rows using insert <<
15:44:27 SQL> INSERT INTO SAM.EMP1 (SELECT * FROM SAM.EMP1 AS OF TIMESTAMP TO_TIMESTAMP ('11-01-2017 15:25:43','DD-MM-YYYY HH24:MI:SS') where comm='250');
24 rows created.
#################################################################################
Same Scenario here But we are Restoring rows of the Hire-date Column because rows are deleted in this table using date.
#################################################################################
15:52:18 SQL> select count(*) from emp1;
COUNT(*)
----------
184
15:52:22 SQL> delete from emp1 where hiredate='24-APR-87';
32 rows deleted.
15:54:27 SQL> SELECT COUNT(*) FROM EMP1;
COUNT(*)
----------
152
16:09:02 SQL> insert into sam.emp1 (select * from sam.emp1 as of timestamp to_timestamp ('11-01-2017 15:52:18', 'DD-MM-YYYY HH24:MI:SS') where HIREDATE='24-APR-87');
32 rows created.
16:11:35 SQL> select count(*) from emp1;
COUNT(*)
----------
184
Happy Learning...