oracle誤刪資料表還原的二種方法(oracle還原)_oracle

來源:互聯網
上載者:User

一、如果是剛剛刪除,那麼有兩方法:

首先用show parameter undo;命令查看當時的資料庫參數undo_retention設定。

顯示如下:

複製代碼 代碼如下:

undo_management   string   AUTO

undo_retention  integer 10800

undo_suppress_errors  boolean  FALSE

undo_tablespace   string   UNDOTBS1

undo_retention(保持力),10800單位是秒。即3個小時。

修改預設的undo_retention參數設定:

複製代碼 代碼如下:

ALTER SYSTEM SET undo_retention=10800 SCOPE=BOTH;

方法1,通過oracle提供的回閃功能:

複製代碼 代碼如下:

exec dbms_flashback.enable_at_time(to_date('2007-07-23 10:21:00','yyyy-mm-dd hh24:mi:ss'));

set serveroutput on

DECLARE r_temp hr.job_history%ROWTYPE;

CURSOR c_temp IS SELECT * FROM hr.job_history;

BEGIN

OPEN c_temp;

dbms_flashback.disable;

LOOP

FETCH c_temp INTO r_temp;

EXIT WHEN c_temp%NOTFOUND;

insert into hr.job_history(EMPLOYEE_ID,JOB_ID,START_DATE,END_DATE) values (r_temp.EMPLOYEE_ID,r_temp.JOB_ID,r_temp.START_DATE,r_temp.END_DATE);

commit;

END LOOP;

CLOSE c_temp;

END;

方法2,insert into hr.job_history

複製代碼 代碼如下:

select * from hr.job_history as of timestamp to_timestamp('2007-07-23 10:20:00', 'yyyy-mm-dd hh24:mi:ss');

這種方法簡單,容易掌握,功能和上面的一樣時間為你誤操作之前的時間,最好是離誤操作比較近的,因為oracle儲存在復原保持段裡的資料時間有一定的時間限制由undo_retention 這個參數值決定。

二、如果是刪除一段時間了,但你有比較新的Database Backup,就通過備份來恢複。建立一個庫,把備份還原上去,匯出表資料,再匯入到現在用的庫中去。

三、如果刪除一段時間了,並且無備份,但是資料在寫入表的時候同時會寫入其它一些關聯表的話,那麼就嘗試通過寫SQL語句從其它表取資料出來insert到被刪除的表中。

四、恢複到備份表中

複製代碼 代碼如下:

create table tableName_bak
as
select * from tableName as of TIMESTAMP to_timestamp('20081126 103435','yyyymmdd hh24miss');

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.