Recover data from truncated tables, you can do it by yourself.
I have seems somebody truncated their tables by mistaken several times, because of they connect to wrong database and run the script without careful check. To save data, the first thing they need to do is stop the database, and take a backup of the tablespace where the tables locate. For truncation, Oracle just reformat the segment header, and other blocks remain untouched, so we are able to recover the data, however if the blocks are touched by oracle again, it will be formatted to hold new rows. Following is an example of how to recover the rows back, let's build a demo table first:
SQL> CREATE TABLE T_TRUNCATE AS SELECT * FROM TAB;
Table created.
SQL> SELECT COUNT(*) FROM T_TRUNCATE;
COUNT(*)
----------
14
SQL> ALTER SYSTEM CHECKPOINT;
System altered.
SQL> TRUNCATE TABLE T_TRUNCATE;
Table truncated.
SQL> ALTER SYSTEM CHECKPOINT;
System altered.
The truncated table will be assigned a new data object id, we could get it from DESC command output:L
AUL> desc anysql.t_truncate
Storage(OBJ#=9976 OBJD=9977 TS=4 FILE=4 BLOCK=5235 CLUSTER=0)
No. SEQ INT Column Name Type
--- --- --- ----------------------------- ----------------
1 1 1 TNAME VARCHAR2(30) NOT NULL
2 2 2 TABTYPE VARCHAR2(7)
3 3 3 CLUSTERID NUMBER
To recover the rows, we need run scan extent command to generate the extent map to a text file (AULEXT.TXT), because segment header is formatted by Oracle.
