Oracle restores data from a certain table in the database at a certain time

If you accidentally delete data during testing, or you need to restore the data and test the SQL repeatedly, you can use Oracle's flashback function to restore the database to a certain point in time.

Recover data to a certain point in time

-- 假设表名为 HOLIDAY

-- 开启行移动
ALTER TABLE HOLIDAY ENABLE ROW MOVEMENT;
-- 恢复数据到某一时刻
FLASHBACK TABLE HOLIDAY TO TIMESTAMP TO_TIMESTAMP('2024-01-15 08:00:00', 'yyyy-mm-dd hh24:mi:ss');
-- 关闭行移动
ALTER TABLE HOLIDAY DISABLE ROW MOVEMENT;
ROW MOVEMENT

If row movement is not enabled, an error will be reported ORA-08189: cannot flashback the table because row movement is not enabled.

Regarding row movement, ChatGPT's answer is as follows:

In Oracle database, enabling row movement (ROW MOVEMENT) is an option used to modify the table definition. It allows specific operations to be performed on the table, such as updating, deleting, and inserting rows, while maintaining a high degree of availability of the table. When you enable row movement, you have more flexibility in modifying the table structure, including modifying the physical storage location of the table's rows.

Query data at a certain time

-- 查询某一时刻的数据
SELECT * FROM HOLIDAY AS OF TIMESTAMP TO_TIMESTAMP('2024-01-15 08:00:00', 'yyyy-mm-dd hh24:mi:ss');

Guess you like

Origin blog.csdn.net/weixin_45883310/article/details/136097618