一、如果是剛剛刪除,那麼有兩方法:
首先用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');