• ORACLE 利用SCN恢复误delete的表


    --kg是误删除的表
    SQL> select count(*) from kg;
      COUNT(*)
    ----------
        820861
    SQL> delete from kg;
    820861 rows deleted
    SQL> commit;
    Commit complete
    SQL> select count(*) from kg;
      COUNT(*)
    ----------
             0
    SQL> rollback;
    Rollback complete
    SQL> select count(*) from kg;
      COUNT(*)
    ----------
             0
    --kg被删除且已经提交。

    --查询此时数据库的SCN
    SQL> select dbms_flashback.get_system_change_number from dual;
    GET_SYSTEM_CHANGE_NUMBER
    ------------------------
                     4915780
    SQL> select count(*) from kg as of scn 4915780;
      COUNT(*)
    ----------
             0
    --创建表howard存放数据库的SCN
    SQL> create table howard(count int,scn int);
    Table created
    SQL> DECLARE
         i INT:=4915600;
         BEGIN
            FOR i IN 4915600..4915782 LOOP
              INSERT INTO howard( SCN) VALUES (i );
              UPDATE howard SET COUNT =(SELECT COUNT(*) FROM kg AS OF SCN i) WHERE SCN= i;
            END LOOP ;
         END ;
         /
    SQL> SELECT * FROM howard
    SQL> /

                                      COUNT                                     SCN
    --------------------------------------- ---------------------------------------
                                     820861                                 4915704
                                     820861                                 4915705
                                     820861                                 4915706
                                          0                                 4915707
                                          0                                 4915708
                                          0                                 4915709

    --得到删除前数据库的SCN,恢复表数据
    SQL>  select count(*) from kg  as of scn 4915706;
      COUNT(*)
    ----------
        820861
    SQL> select count(*) from kg  as of scn 4915707;
      COUNT(*)
    ----------
             0
    SQL> insert into kg select * from kg as of scn 4915706;
    820861 rows inserted
    SQL> drop table howard;
    Table dropped
    SQL> commit;
    Commit complete
  • 相关阅读:
    java连接各种数据库
    java遗传算法
    java中‘==’和’equal‘的区别
    java.net.BindException: Address already in use: JVM_Bind错误,端口设置问题
    Flink学习笔记6 Flink原理-Task(任务)、Operator Chain(算子链)和Slot(资源)
    Flink学习笔记5 Flink原理-资源
    Flink学习笔记4 Flink原理-基础架构
    Flink学习笔记2 CentOS7.5搭建Flink1.6.1分布式集群
    Flink学习笔记1 Flink入门简介
    Dubbo学习笔记12:使用Dubbo中需要注意的一些事情
  • 原文地址:https://www.cnblogs.com/sddychj/p/4627337.html
Copyright © 2020-2023  润新知