DELETE误操作_oracle

对于DELETE的误操作
当不小心用DELETE删除了表中的一条或多条记录的恢复

1,基于时间的闪查
闪查的查询能力是受到undo表空间的大小和undo_retention的影响
以SCOTT.EMP为例子简单示范下
SQL> SHOW USER
USER is "SCOTT"

SQL> SELECT COUNT(*) FROM EMP;

  COUNT(*)
----------
        14

SQL> DELETE EMP WHERE ENAME='SCOTT';

1 row deleted.

SQL> COMMIT;

Commit complete.

SQL> SELECT COUNT(*) FROM EMP;

  COUNT(*)
----------
        13

SQL> SELECT * FROM EMP AS OF TIMESTAMP SYSDATE-5/1440 WHERE ENAME='SCOTT';
    (上一个5分钟之内的,1440表示24*60,也可以根据自己定义的时间格式来写具体的时间)

EMPNO ENAME      JOB          MGR HIREDATE              SAL  COMM     DEPTNO
----- ---------- ---------- ----- ------------------- ----- ----- ----------
 7788 SCOTT      ANALYST     7566 1987-04-19 00:00:00  3000               20

SQL> INSERT INTO EMP SELECT * FROM EMP AS OF TIMESTAMP SYSDATE-5/1440 WHERE ENAME='SCOTT';

1 row created.

SQL> SELECT COUNT(*) FROM EMP;

  COUNT(*)
----------
        14

SQL> COMMIT;

Commit complete.

2,基于SCN的闪查(删除的步骤就不重复了)
SQL> SHOW USER
USER is "SYS"


SQL> SELECT SCN,TIME_DP FROM (SELECT SCN,TIME_DP FROM SMON_SCN_TIME ORDER BY TIME_DP DESC) WHERE ROWNUM<5;

       SCN TIME_DP
---------- -------------------
    874277 2011-06-18 01:05:48
    874073 2011-06-18 01:00:21
    873920 2011-06-18 00:59:57
    873774 2011-06-18 00:54:27
    (5分钟一写,可以根据时间查询SCN来进行恢复.)
SQL> SELECT * FROM SCOTT.EMP AS OF SCN 873774 WHERE ENAME='SCOTT';

EMPNO ENAME      JOB          MGR HIREDATE              SAL  COMM     DEPTNO
----- ---------- ---------- ----- ------------------- ----- ----- ----------
 7788 SCOTT      ANALYST     7566 1987-04-19 00:00:00  3000               20



注:初学者,欢迎指点,不断改进。doo


 

本文出自 “doo” 博客,谢绝转载!

你可能感兴趣的:(oracle,职场,delete,休闲,误操作)