2014-12-05 37 views
4

我做了一個數據庫更新,而不使用where子句並提交而沒有進行任何備份。表中的所有行均已更新。有什麼方法可以回滾更改嗎?如何在提交後回滾數據庫更改?

該DB是一個Oracle SQL之一。請幫忙。

+0

你不能回滾已經取得的COMMITED – Richa 2014-12-05 06:02:27

+0

嘗試使用閃回https://docs.oracle.com/cd/B12037_01/server.101/b10759/statements_9012.htm – Exhausted 2014-12-05 06:03:15

+0

爲什麼你同時擁有'sql-server'和'oracle'標籤GETHER。我的答案是針對Oracle數據庫的。 – 2014-12-05 07:31:45

回答

19

你可以使用Flashback功能。

1.Flashback通過SCN

SELECT column_list 
FROM table_name 
AS OF SCN scn_number; 

2.Flashback由TIMESTAMP

SELECT column_list 
FROM table_name 
AS OF TIMESTAMP TO_TIMESTAMP('the timestamp value'); 

要獲得CURRENT_SCN和SYSTIMESTAMP,查詢:

SELECT current_scn, SYSTIMESTAMP 
FROM v$database; 

讓我們看一個爲例e:

要將表閃回到舊的scn,請使用FLASHBACK TABLE..TO SCN子句。

SQL> DROP TABLE string_ex PURGE; 

Table dropped. 

SQL> CREATE TABLE string_ex (sl_ps_code VARCHAR2(20)); 

Table created. 

SQL> INSERT INTO string_ex (sl_ps_code) VALUES ('AR14ASM0002'); 

1 row created. 

SQL> INSERT INTO string_ex (sl_ps_code) VALUES ('AR14SFT0018'); 

1 row created. 

SQL> INSERT INTO string_ex (sl_ps_code) VALUES ('AR14SFT0019'); 

1 row created. 

SQL> INSERT INTO string_ex (sl_ps_code) VALUES ('AR14SFT0062'); 

1 row created. 

SQL> COMMIT; 

Commit complete. 

SQL> SELECT current_scn, SYSTIMESTAMP FROM v$database; 

     CURRENT_SCN SYSTIMESTAMP 
-------------------- -------------------------------------------- 
     13818123201277 29-OCT-14 03.02.17.419000 PM +05:30 

SQL> SELECT current_scn, SYSTIMESTAMP FROM v$database; 

     CURRENT_SCN SYSTIMESTAMP 
-------------------- -------------------------------------------- 
     13818123201280 29-OCT-14 03.02.22.785000 PM +05:30 

SQL> SELECT current_scn, SYSTIMESTAMP FROM v$database; 

     CURRENT_SCN SYSTIMESTAMP 
-------------------- -------------------------------------------- 
     13818123201282 29-OCT-14 03.02.26.781000 PM +05:30 

SQL> SELECT * FROM string_ex; 

SL_PS_CODE 
--------------- 
AR14ASM0002 
AR14SFT0018 
AR14SFT0019 
AR14SFT0062 

SQL> 

我有表四行。

SQL> ALTER TABLE string_ex ENABLE ROW MOVEMENT; 

Table altered. 

SQL> 

行移動是必需的。

SQL> DELETE FROM string_ex WHERE ROWNUM =1; 

1 row deleted. 

SQL> 
SQL> COMMIT; 

Commit complete. 

SQL> 
SQL> SELECT * FROM string_ex; 

SL_PS_CODE 
--------------- 
AR14SFT0018 
AR14SFT0019 
AR14SFT0062 

我現在刪除了一行並提交更改。

SQL> FLASHBACK TABLE string_ex TO SCN 13818123201277; 

Flashback complete. 

閃回完成

SQL> SELECT * FROM string_ex; 

SL_PS_CODE 
--------------- 
AR14ASM0002 
AR14SFT0018 
AR14SFT0019 
AR14SFT0062 

SQL> 

現在我有表,舊的國家和行是回

相關問題