再也不用因Delete操作误删数据担心被Boss骂啦!!
[backcolor=rgb(248, 248, 248)]怎么找回因Delete操作而误删的数据呢?
[backcolor=rgb(248, 248, 248)]--DELETE,误删之后,想回收数据
[backcolor=rgb(248, 248, 248)]--比如test_tbl
[backcolor=rgb(248, 248, 248)]SELECT COUNT(*) FROM test_tbl;
[backcolor=rgb(248, 248, 248)]--1.勿删test_tbl数据
[backcolor=rgb(248, 248, 248)]DELETE FROM test_tbl;
[backcolor=rgb(248, 248, 248)]--2.根据勿删数据时的时间去获取SCN(System Commit Number)
[backcolor=rgb(248, 248, 248)]SELECT TIMESTAMP_TO_SCN(TO_TIMESTAMP('2013-07-16 11:00:00','YYYY-MM-DD HH:MI:SS')) AS SCN
[backcolor=rgb(248, 248, 248)]FROM DUAL;
[backcolor=rgb(248, 248, 248)]--3.比如说是test_tbl表数据被删,根据SCN找到被删前的记录
[backcolor=rgb(248, 248, 248)]SELECT COUNT(*) FROM test_tbl AS OF SCN 14273584;
[backcolor=rgb(248, 248, 248)]PS:14273584 是SCN号
[backcolor=rgb(248, 248, 248)]--4.移回被删数据(这里可以创建一个临时表,去和正式表比对,找回必要的数据)
[backcolor=rgb(248, 248, 248)]INSERT INTO test_tbl SELECT * FROM test_tbl AS OF SCN 14273584;
[backcolor=rgb(248, 248, 248)]
[backcolor=rgb(248, 248, 248)]CREATE TABLE test_tmp_tbl AS SELECT * FROM test_tbl AS OFSCN 14273584;