In the Oracle database, if you accidentally delete the data, the data is how to restore it?
There are two methods: scn method and time stamp method
First, recover deleted data SQL syntax (recommended timestamp)
1 to remove and recover by scn submitted data
1) Get the current scn number of the database
select current_scn from v $ database; (sys switch to query the user or user system)
Queried scn number: 1499223
2) prior to the current number of queries scn scn
select * from table name as of scn 1499220; (determining whether to delete the data exists, if there is, then restore the data; if not, continue to shrink scn number)
3) recover deleted data and has been submitted
flashback table 表名 to scn 1499220;
2, by deleting the recovery time and the data submitted
1) to query the current system time
select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from dual;
2) query data delete data point of time
select * from table as of timestamp to_timestamp ( '2018-10-09 15:29:00', 'yyyy-mm-dd hh24: mi: ss'); (if not, continue to narrow)
3) recover deleted data and has been submitted
- Enable row movement (to solve the following problem statement error)
alter table 表名 enable row movement;
- restore data to a point in time
flashback table 表名 to timestamp to_timestamp('2018-10-09 15:29:00','yyyy-mm-dd hh24:mi:ss');
- Close the row movement
alter table 表名 disable row movement;
Second, the example (method) to recover deleted data
1, before deleting data table query data
- Query before deleting data table --- the SELECT * from Dxc_Goods;
2, delete data operations (132, 133), and view
- delete operation: 132,133-- the Delete from Dxc_GOODS the WHERE MID in ( 132 , 133 ); - submit (analog accidental deletion operation) the commit ;
View Results
3, undelete and data submitted (to delete the specified point in time, to ensure that this is the time before delete)
- open row movement (to solve the following problem statement error) the ALTER the Table Dxc_Goods enable Row Movement NC Joining Module; - recovery of data some point in time the Flashback the Table Dxc_Goods to timestamp to_timestamp ( ' 2019-07-24 18:00:00 ' , ' YYYY-mm-dd HH24: mi The: SS ' ); - closing row movement ALTER Table Dxc_Goods disable row movement;
After executing the query data (132,133 data has been restored)
PS:
Reference URL: https: //blog.csdn.net/qq_36460189/article/details/82983732