Oracle 刪除表資料 找回方法

2021-08-08 19:56:42 字數 1718 閱讀 2860

oracle 有個東西要scn 叫做 system change number 大概就是你對資料庫做的任何改變都會 被oracle 記錄下來

很多概念的東西可以去看看 oracle concept 和官方文件 比如索引 鎖 資料塊 區  表空間,表連線, 以及 oracle各個後台程序工作原理 等等(這裡推薦看收穫不止oracle 和 oracle concept )

了解了原理 你才能知道 你編寫的一條sql 前前後後是如何工作的,對系統做出哪些影響,你才能優化sql

select * from recyclebin t where t.original_name='test1'
刪除的表因為表名不存在了 所以要去**站找

flashback table *** to before drop; #閃回剛刪除的表
如果drop table test1  其實 oracle 只是把錶放入**站 能夠找回的,但是限於時間 與 undo 表空間大小

flashback table *** to scn/timestamp [enable trigger]
scn 表示 system change number, timestamp 表示時間戳

select * from sys.smon_scn_time t order by t.scn # 查詢 scn  timestamp 

flashback table *** to before drop rename to ***x
另外 在短時間內對錶做出delete update insert 操作

oracle 都是能查詢到的 如下 查詢最近20分鐘 內 對test1 的delete insert update 操作 

select id,name,versions_startscn,versions_endscn,versions_operation

from test1 versions between scn timestamp_to_scn(sysdate-20/1440) and

scn timestamp_to_scn(sysdate)

其中 id name 是屬於 test1 表的字段

select * from flashback_transaction_query

查詢五分鐘前test1 的資料

select * from test1 as of timestamp sysdate - 5/1400;
查詢scn 編號 時刻 test1 的資料

select * from test1 as of scn 20682041
查詢系統scn

select * from sys.smon_scn_time t order by t.scn

select dbms_flashback.get_system_change_number from dual;

scn 與 timestamp 對應轉換

select to_char(scn_to_timestamp(20680565),'yyyy-mm-dd hh:mi:ss') from dual

select timestamp_to_scn(sysdate) from dual;

Oracle資料刪除後找回

檢視當前scn數值 select dbms flashback.get system change number from dual scn與時間的對應關係 select to char sysdate,yyyy mm dd hh24 mi ss to char dbms flashback.get...

找回oracle中刪除的資料

select dbms flashback.get system change number from dual 查詢當前scn號 如果不知道刪除之前的scn號,可以進行閃回查詢 即,數字一直減小,直到找到為止 select count from table1 as of scn 205125720...

oracle找回被刪除的資料

oracle中如果進行裡的delete如果想要恢復 例如檢視某一張表 select from vts users 發現有2條資料 然後執行刪除表資料操作 delete from vts users 這是檢視scn資料 select dbms flashback.get system change n...