search
HomeDatabaseMysql TutorialOracle用delete命令删除数据恢复

操作的数据库为Oracle 10g , 之前删除方式为delete 不晓得trancate好使不,究竟是哪个词其实对我们来说并不是最重要的,重要的是

同事找回时操作的数据库为Oracle 10g , 之前删除方式为delete 不晓得trancate好使不。

SCN(系统改变号),它的英文全拼为:System Change Number ,它是数据库中非常重要的一个数据结构。

SCN提供了Oracle的内部时钟机制,可被看作逻辑时钟,这对于恢复操作是至关重要的。

注释:Oracle 仅根据 SCN 执行恢复。

它定义了数据库在某个确切时刻提交的版本。在事物提交时,它被赋予一个唯一的标示事物的SCN 。一些人认为 SCN 是指, System Commit Number ,而通常 SCN 在提交时才变化,,所以很多情况下,这两个名词经常被交替使用。

究竟是哪个词其实对我们来说并不是最重要的,重要的是我们知道 SCN 是 Oracle 内部的时钟机制, Oracle 通过 SCN 来维护数据库的一致性,并通过SCN 实施 Oracle 至关重要的恢复机制。

具体执行流程我们可从以下几个示例图中体会;

1.原表记录 $ sqlplus eygle/eygle

SQL*Plus: Release 10.1.0.2.0 - Production on Wed Mar 30 08:52:04 2005

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

Connected to:

Oracle Database 10g Enterprise Edition Release 10.1.0.2.0 - 64bit Production

With the Partitioning, OLAP and Data Mining options

SQL>select count(*) from t1;

COUNT(*)

----------

9318

2.误删除所有记录

并且提交更改。

SQL>delete from t1;

9318 rows deleted.

SQL>commit;

Commit complete.

SQL>select count(*) from t1;

COUNT(*)

----------

0

3.获得当前SCN

如果能够确切知道删除之前SCN最好,如果不知道,可以进行闪回查询尝试.

SQL>select dbms_flashback.get_system_change_number from dual;

GET_SYSTEM_CHANGE_NUMBER

------------------------

10671006

SQL>select count(*) from t1 as of scn 10671000;

COUNT(*)

----------

0

SQL>select count(*) from t1 as of scn 10670000;

COUNT(*)

----------

9318

我们看到在SCN=10670000时,数据都在。

4.恢复数据.

SQL>insert into t1 select * from t1 as of scn 10670000;

9318 rows created.

SQL>commit;

Commit complete.

SQL>select count(*) from t1;

COUNT(*)

----------

9318

文章2

误删数据后的还原

select timestamp_to_scn(to_timestamp('2009-03-13 09:00:00','YYYY-MM-DD HH:MI:SS')) from dual;

结果:13526973

将删除时间转换为scn

select * from reportinfo

AS OF SCN 13526973

将reportinfo表中的scn点的数据取出

然后可以根据这个数据进行还原操作

create table reporttest as select * from reportinfo where 1=0;

insert into reporttest select * from reportinfo AS OF SCN 13526973;

--上面两句应该可以合成一句

--create table reporttest as select * from reportinfo AS OF SCN 13526973;

这是reporttest表中就是scn点的reportinfo数据.处理即可

linux

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
How does MySQL handle data replication?How does MySQL handle data replication?Apr 28, 2025 am 12:25 AM

MySQL processes data replication through three modes: asynchronous, semi-synchronous and group replication. 1) Asynchronous replication performance is high but data may be lost. 2) Semi-synchronous replication improves data security but increases latency. 3) Group replication supports multi-master replication and failover, suitable for high availability requirements.

How can you use the EXPLAIN statement to analyze query performance?How can you use the EXPLAIN statement to analyze query performance?Apr 28, 2025 am 12:24 AM

The EXPLAIN statement can be used to analyze and improve SQL query performance. 1. Execute the EXPLAIN statement to view the query plan. 2. Analyze the output results, pay attention to access type, index usage and JOIN order. 3. Create or adjust indexes based on the analysis results, optimize JOIN operations, and avoid full table scanning to improve query efficiency.

How do you back up and restore a MySQL database?How do you back up and restore a MySQL database?Apr 28, 2025 am 12:23 AM

Using mysqldump for logical backup and MySQLEnterpriseBackup for hot backup are effective ways to back up MySQL databases. 1. Use mysqldump to back up the database: mysqldump-uroot-pmydatabase>mydatabase_backup.sql. 2. Use MySQLEnterpriseBackup for hot backup: mysqlbackup--user=root-password=password--backup-dir=/path/to/backupbackup. When recovering, use the corresponding life

What are some common causes of slow queries in MySQL?What are some common causes of slow queries in MySQL?Apr 28, 2025 am 12:18 AM

The main reasons for slow MySQL query include missing or improper use of indexes, query complexity, excessive data volume and insufficient hardware resources. Optimization suggestions include: 1. Create appropriate indexes; 2. Optimize query statements; 3. Use table partitioning technology; 4. Appropriately upgrade hardware.

What are views in MySQL?What are views in MySQL?Apr 28, 2025 am 12:04 AM

MySQL view is a virtual table based on SQL query results and does not store data. 1) Views simplify complex queries, 2) Enhance data security, and 3) Maintain data consistency. Views are stored queries in databases that can be used like tables, but data is generated dynamically.

What are the differences in syntax between MySQL and other SQL dialects?What are the differences in syntax between MySQL and other SQL dialects?Apr 27, 2025 am 12:26 AM

MySQLdiffersfromotherSQLdialectsinsyntaxforLIMIT,auto-increment,stringcomparison,subqueries,andperformanceanalysis.1)MySQLusesLIMIT,whileSQLServerusesTOPandOracleusesROWNUM.2)MySQL'sAUTO_INCREMENTcontrastswithPostgreSQL'sSERIALandOracle'ssequenceandt

What is MySQL partitioning?What is MySQL partitioning?Apr 27, 2025 am 12:23 AM

MySQL partitioning improves performance and simplifies maintenance. 1) Divide large tables into small pieces by specific criteria (such as date ranges), 2) physically divide data into independent files, 3) MySQL can focus on related partitions when querying, 4) Query optimizer can skip unrelated partitions, 5) Choosing the right partition strategy and maintaining it regularly is key.

How do you grant and revoke privileges in MySQL?How do you grant and revoke privileges in MySQL?Apr 27, 2025 am 12:21 AM

How to grant and revoke permissions in MySQL? 1. Use the GRANT statement to grant permissions, such as GRANTALLPRIVILEGESONdatabase_name.TO'username'@'host'; 2. Use the REVOKE statement to revoke permissions, such as REVOKEALLPRIVILEGESONdatabase_name.FROM'username'@'host' to ensure timely communication of permission changes.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor