2015-01-09 41 views
0

具有巨大的數據我在Oracle審計表,其數據增長速度非常快,已經成爲非常大的 看,我已經決定不審計剪短它' CALLED_TIME'列。集團通過其在甲骨文

因此,我需要刪除記錄審計記錄爲CALLED_TIME審計表,然後我想從我的表中刪除CALLED_TIME列(這很容易),讓它不被進一步記錄。

這將是更好,如果我能列出轉速將被刪除

數據之前

REV  CALLED_TIME    REVTYPE DATA1 DATA2 DATA3 
239402 2014-08-20 20:48:20  0  12122 4  22 
239403 2014-08-20 20:52:17  1  12122 4  22 
239404 2014-08-20 20:52:58  1  12122 4  22 
239405 2014-08-20 20:53:13  1  12122 4  22 
239406 2014-08-20 20:53:13  1  12122 4  223 
239407 2014-08-20 21:02:05  1  12122 4  223 
239408 2014-08-20 21:02:39  1  12122 4  223 
239409 2014-08-20 21:04:22  1  12122 4  223 
239410 2014-08-20 21:27:53  1  12122 4  223 
239411 2014-08-20 21:28:51  1  12122 4  223 
239412 2014-08-20 21:29:50  1  12122 4  223 
239413 2014-08-20 21:29:50  1  12122 43  223 
239414 2014-08-20 21:46:19  1  12122 43  223 
239415 2014-08-20 21:46:51  1  12122 43  223 
239416 2014-08-20 21:53:08  1  12122 43  223 
239417 2014-08-20 22:00:45  1  12122 43  223 
239418 2014-08-20 22:01:26  1  12122 43  223 
239419 2014-08-20 22:23:01  1  111141 43  223 
239420 2014-08-20 22:23:48  1  111141 43  223 
239421 2014-08-20 22:32:11  1  111141 43  223 
239422 2014-08-20 22:44:42  1  111141 43  223 
239423 2014-08-20 22:46:38  1  111141 43  223 
239414 2014-08-20 22:55:33  2  111141 43  223 

輸出應該像

REV  CALLED_TIME    REVTYPE DATA1 DATA2 DATA3 
239402 2014-08-20 20:48:20  0  12122 4  22 
239406 2014-08-20 20:53:13  1  12122 4  223 
239413 2014-08-20 21:29:50  1  12122 43  223 
239419 2014-08-20 22:23:01  1  111141 43  223 
239414 2014-08-20 22:55:33  2  111141 43  223 

我已經看了很多相關的解決方案,但我選擇的是連接表兩次,因此變得非常懶惰。

回答

2

從你的樣本數據,它看起來像要刪除大部分的記錄。因此,這是最好的方法是創建一個表,要保留,然後就扎普你的原始表中的數據的情況。

create table temp_audit as 
    select * from (
     select t.* 
       , row_number() over (partition by REVTYPE, DATA1, DATA2, DATA3 
            order by CALLED_TIME asc) rn 
      from orig_audit 
      ) 
    when rn = 1; 

然後您需要放棄原始表並替換保留的表。最快的方法可能是:

drop table orig_audit; 
rename temp_audit to orig_audit; 

但是,如果你有很多索引,授予,外鍵來恢復,可能不那麼快。備擇方案?如果沒有外鍵引用表,那麼這將這樣的伎倆......

truncate table orig_audit; 
insert into orig_audit 
    select * from temp_audit; 

...否則...

delete from orig_audit; 
insert into orig_audit 
    select * from temp_audit;