J2EE社區(qū)

          茍有恒,何必三更起五更眠;
          最無(wú)益,只怕一日曝十日寒.
          posts - 241, comments - 318, trackbacks - 0, articles - 16

          oracle數(shù)據(jù)恢復(fù)

          Posted on 2011-12-23 10:33 xcp 閱讀(4762) 評(píng)論(2)  編輯  收藏 所屬分類: Database
           1.
          表查詢閃回
          create table xcp as (select * from b_za_bzdzkxx);
          select * from xcp;
          select count(1) from xcp;--22001
          select count(1) from xcp t where t.dzbh like '510521%';--7011
          delete from xcp t where t.dzbh like '510521%';
          select count(1) from xcp;--14990
          --查找指定時(shí)間點(diǎn)前的數(shù)據(jù)
          select count(1) from xcp as of timestamp to_timestamp('2011-12-23 10:49:30','yyyy-MM-dd hh24:mi:ss');--22001

          select * from xcp for update;--添加一條記錄
          select count(1) from xcp;--14991

          --恢復(fù)指定時(shí)間點(diǎn)的前delete數(shù)據(jù)(將刪除恢復(fù)時(shí)間點(diǎn)后面的數(shù)據(jù))

          alter table xcp enable row movement;--啟動(dòng)的行移動(dòng)功能
          flashback table xcp to timestamp to_timestamp('2011-12-23 10:49:30','yyyy-MM-dd hh24:mi:ss');
          select count(1) from xcp;--22001

          --恢復(fù)指定時(shí)間點(diǎn)的前delete數(shù)據(jù),并保留恢復(fù)時(shí)間點(diǎn)后面的數(shù)據(jù)

          create table xcp2 as (select * from xcp t where t.createdtime>to_timestamp('2011-12-23 10:49:30','yyyy-MM-dd hh24:mi:ss'));
          select * from xcp2;--臨時(shí)表
          alter table xcp enable row movement;--啟動(dòng)的行移動(dòng)功能
          flashback table xcp to timestamp to_timestamp('2011-12-23 10:49:30,'yyyy-MM-dd hh24:mi:ss');
          select count(1) from xcp;--22001
          insert into xcp select * from xcp2 --將臨時(shí)表的數(shù)據(jù)再插入到源表
          select count(1) from xcp;--22002


          2.刪除
          閃回[10g+]
              刪除閃回為刪除oracle 10G提供了一個(gè)數(shù)據(jù)庫(kù)安全機(jī)制,當(dāng)用戶刪除一個(gè)表時(shí),oracle 10G會(huì)將該表放到回收站中,回收站中的對(duì)象一直會(huì)保留,直到用戶決定永久刪除它們或出現(xiàn)表空間的空間不足時(shí)才會(huì)被刪除。回收站是一個(gè)虛擬容器,用于存儲(chǔ)所有被刪除的對(duì)象。數(shù)據(jù)字典user_tables中的列dropped表示被刪除的表,查詢方法如下:
          select table_name,dropped from user_tables;
          --設(shè)置數(shù)據(jù)庫(kù)是否啟用回收站
          alert session set recyclebin = off;
          --查詢回收站對(duì)象
          select * from recyclebin;
          select * from user_recyclebin;
          select * from dba_recyclebin;


          drop table xcp;
          select count(1) from xcp;--0
          --恢復(fù)drop的表
          flashback table xcp to before drop;
          select count(1) from xcp;--22001

          如果不知道原表名,可以直接使用回收站中的名稱進(jìn)行閃回..
          flashback table "BIN$JiXyAUO4R+u3qNVfQK/Kiw==$0" to before drop;
          在回收的同時(shí)可以修改表名
          flashback table "
          BIN$JiXyAUO4R+u3qNVfQK/Kiw==$0" to before drop rename to xcp1;

          --真正刪除一個(gè)表,而不進(jìn)入回收站,可以在刪除表時(shí)增加purge選項(xiàng)
          drop table xcp1 purge;
          --也可以從回收站永久性刪除表
          purge table xcp1;
          --刪除當(dāng)前用戶回收站
          purge recyclebin
          --刪除全體用戶在回收站的資源
          purge dba_resyclebin



          3.數(shù)據(jù)庫(kù)閃口
          [10g+]
              使用數(shù)據(jù)庫(kù)閃回功能,可以使數(shù)據(jù)庫(kù)回到過(guò)去某一狀態(tài),語(yǔ)法如下:
                  sql: alter database flashback on;
                  sql: flashback database to scn 46963;
                  sql: flashback database to timestamp to_timestamp('2007-2-12 12:00:00','yyyy-MM-dd hh24:mi:ss');



          注:表結(jié)構(gòu)修改后不能直接恢復(fù)
          http://blog.csdn.net/colin_liu2009/article/details/6906548

          http://www.xifenfei.com/2012/06/%E5%88%A9%E7%94%A8flashback-database%E5%AE%9E%E7%8E%B0%E9%83%A8%E5%88%86%E5%AF%B9%E8%B1%A1%E5%9B%9E%E6%BB%9A.html



          名稱: ?4C.ESL | .↗Evon
          口號(hào): 遇到新問(wèn)題?先要尋找一個(gè)方案乄而不是創(chuàng)造一個(gè)方案こ
          mail: 聯(lián)系我


          Feedback

          # re: oracle中恢復(fù) drop表或delete數(shù)據(jù)  回復(fù)  更多評(píng)論   

          2011-12-23 14:04 by 瘋狂
          9i不行

          # re: oracle中恢復(fù) drop表或delete數(shù)據(jù)  回復(fù)  更多評(píng)論   

          2011-12-23 15:43 by xcp
          @瘋狂
          恩 要10G的以上
          主站蜘蛛池模板: 连城县| 安化县| 通山县| 永平县| 县级市| 株洲县| 河西区| 巴塘县| 西青区| 五莲县| 东安县| 巴中市| 宝坻区| 家居| 新巴尔虎左旗| 商洛市| 阿瓦提县| 宁河县| 和政县| 宜良县| 绵阳市| 鄄城县| 依安县| 阿城市| 南投县| 盐亭县| 东山县| 卢龙县| 临湘市| 合肥市| 万山特区| 上高县| 航空| 枣庄市| 乐都县| 平和县| 景德镇市| 渭南市| 拜城县| 天津市| 鄂州市|