Get the App
SLTechnology News&Howtos  ›  Database  › 

Using fy_recover_data to recover the data of truncate table

Shulou Source: shulou.com Published: 2022-06-01 06:22:13 11月15日 Update

1. @ / home/oracle/FY_Recover_Data.SQL

Create the required package

[oracle@localhost oradata] $sqlplus / as sysdba

SQL*Plus: Release 11.2.0.4.0 Production on Thu May 17 00:43:59 2018

Copyright (c) 1982, 2013, Oracle. All rights reserved.

Connected to:

Oracle Database 11g Enterprise Edition Release 11.2.0.4.0-64bit Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options

SQL > @ / home/oracle/FY_Recover_Data.SQL

Package created.

Package body created.

two。 Create test data:

Create table scott.test_emp tablespace users as select * from scott.emp

Truncate table scott.test_emp

3. Execute the script:

Note the path: the last "/" of "/ u01/app/oracle/oradata/orcl/" cannot be missing.

DECLARE

Tgtowner VARCHAR2 (30)

Tgttable VARCHAR2 (30)

Datapath VARCHAR2 (4000)

Datadir VARCHAR2 (30)

Rects VARCHAR2 (30)

Recfile VARCHAR2 (30)

Rstts VARCHAR2 (30)

Rstfile VARCHAR2 (30)

Blksz NUMBER

Rectab VARCHAR2 (30)

Rsttab VARCHAR2 (30)

Copyfile VARCHAR2 (30)

BEGIN

Tgtowner: = 'SCOTT';-- table owner

Tgttable: = 'TEST_EMP';-- table name

Datapath:-- must be the same as the directory of the data file where the test.t1 table is located

Datadir: = 'FY_DATA_DIR';-- the name of the directory in oracle, which can be modified

Fy_recover_data.prepare_files (tgtowner

Tgttable

Datapath

Datadir

Rects

Recfile

Rstts

Rstfile

Blksz)

Fy_recover_data.fill_blocks (tgtowner

Tgttable

Datadir

Rects

Recfile

Rstts

eight,

Tgtowner

Tgtowner

Rectab

Rsttab

Copyfile)

Fy_recover_data.recover_table (tgtowner

Tgttable

Tgtowner

Rectab

Tgtowner

Rsttab

Datadir

Datadir

Recfile

Datadir

Copyfile

Blksz)

END

After the execution is complete, you will see that the scott user has added more tables:

SQL > select table_name, tablespace_name from dba_tables where owner = 'SCOTT'

TABLE_NAME TABLESPACE_NAME

DEPT USERS

EMP USERS

BONUS USERS

SALGRADE USERS

TEST_EMP$ FY_REC_DATA

TEST_EMP$$ FY_RST_DATA

TEST_EMP USERS

7 rows selected.

Insert TEST_EMP$$ back into TEST_EMP

FY_Recover_Data.sql

Reference: http://www.hellodba.com/reader.php?ID=191&lang=cn

Tags: Data directory same name location file user script path reference test Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple macOS Redmi OPPO Reno Shulou Information