回滚命令不起作用 - Oracle

发布于 2024-12-27 23:02:55 字数 247 浏览 2 评论 0原文

我删除了一个表并尝试回滚,但没有用。它会像这样工作还是我在这里玩错了?

从大多数评论来看,我清楚 DDL 语句不能通过回滚来撤消,而只能通过闪回来撤消。

我尝试撤消 从学生中删除;

它仍然无法撤消:

我的执行顺序是

  • INSERT,

  • DELETE FROM,

  • ROLLBACK。

I dropped a table and tried to rollback, but to no use. Will it ever work like this or am I playing wrong here?

As from most of the comments I am clear that DDL statements cannot be undone by rollback but only by FLASHBACK.

I tried undoing
DELETE FROM STUDENT;

It still it can't be undone:

My order of execution was

  • INSERT,

  • DELETE FROM ,

  • ROLLBACK.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

故人爱我别走 2025-01-03 23:02:55

我不相信回滚会撤消架构更改。

I don't believe rollback will undo schema changes.

内心荒芜 2025-01-03 23:02:55

没有保存点限定符的ROLLBACK将回滚整个当前事务。

对于 DDL 语句,当前没有要回滚的事务。 DDL 语句在语句开始之前和完成之后隐式生成 COMMIT。因此,如果您在 DROP 之后发出 ROLLBACK,则当前事务中尚未完成任何工作,因此无需回滚。

对于 DML 语句,您将回滚整个当前事务。如果您执行

  • INSERT
  • DELETE
  • ROLLBACK,

那么您的事务将在您执行 INSERT 操作时开始。因此,当您发出 ROLLBACK 时,您将同时回滚 INSERTDELETE,因此表中将恢复为没有数据的状态(假设您开始时没有数据)。如果您在INSERT之后COMMIT,那么下一个事务将以DELETE开始,并且您的ROLLBACK只会回滚DELETE 操作。或者,您可以在 INSERT 之后声明一个保存点并回滚到该保存点

SQL> create table foo( col1 number );

Table created.

SQL> insert into foo values( 1 );

1 row created.

SQL> savepoint after_insert;

Savepoint created.

SQL> delete from foo;

1 row deleted.

SQL> rollback to savepoint after_insert;

Rollback complete.

SQL> select * from foo;

      COL1
----------
         1

ROLLBACK without a savepoint qualifier will roll back the entire current transaction.

For DDL statements, there is no current transaction to rollback. The DDL statement implicitly generates a COMMIT before the statement starts and after it completes. So if you issue a ROLLBACK following a DROP, no work has been done in the current transaction so there is nothing to roll back.

For DML statements, you'll roll back the entire current transaction. If you do

  • INSERT
  • DELETE
  • ROLLBACK

your transaction begins when you execute the INSERT operation. So when you issue the ROLLBACK, you are rolling back both the INSERT and the DELETE so you're back to having no data in the table (assuming you started with no data). If you COMMIT after the INSERT then the next transaction would begin with the DELETE and your ROLLBACK will only roll back the DELETE operation. Alternately, you can declare a savepoint after the INSERT and roll back to the savepoint

SQL> create table foo( col1 number );

Table created.

SQL> insert into foo values( 1 );

1 row created.

SQL> savepoint after_insert;

Savepoint created.

SQL> delete from foo;

1 row deleted.

SQL> rollback to savepoint after_insert;

Rollback complete.

SQL> select * from foo;

      COL1
----------
         1
别在捏我脸啦 2025-01-03 23:02:55

回滚不会撤消架构更改,但要撤消删除表操作,您可以检查:

http://docs.oracle.com/cd/B19306_01/backup.102/b14192/flashptr004.htm

Rollback does not undo schema changes, but to undo drop table operations you can check:

http://docs.oracle.com/cd/B19306_01/backup.102/b14192/flashptr004.htm

以可爱出名 2025-01-03 23:02:55

来自文档

Oracle 数据库在每个 DDL 语句之前和之后隐式提交当前事务。

这意味着您无法ROLLBACK DDL 语句(即架构更改)。

From the documentation:

Oracle Database implicitly commits the current transaction before and after every DDL statement.

This means that you cannot ROLLBACK a DDL statement (that is, a schema change).

煮酒 2025-01-03 23:02:55

回滚永远不会撤消数据定义命令,例如 drop table alter table 等。

Rollback will never undo Data Definition commands such as drop table alter table etc.

怪异←思 2025-01-03 23:02:55

删除表会更改数据库的结构(使用DDL语句,例如创建、删除……)。

COMMIT 和 ROLLBACK 仅适用于使用 DML 与数据库交换的数据 a> 语句(如 INSERT、UPDATE,...)。

所以,不,它永远不会像这样工作。

Dropping a table changes the structure of the database (using DDL statements like CREATE, DROP, ...).

COMMIT and ROLLBACK only work on the data which is exchanged with the database using DML statements (like INSERT, UPDATE, ...).

So, no it will never work like this.

仅此而已 2025-01-03 23:02:55

要回滚 ddl 更改,您需要使用 Flashback。

To rollback ddl changes you need to use Flashback.

千と千尋 2025-01-03 23:02:55

回滚:

使用 ROLLBACK 语句放弃所有挂起的更改。 ROLLBACK 语句之后:

  • 数据更改被撤消。
  • 数据之前的状态被恢复。
  • 受影响行上的锁被释放。

示例

当尝试从 TEST 表中删除记录时,您可能会意外清空该表。您可以更正错误,重新发出正确的语句,并使数据更改永久化。

DELETE FROM test;
25,000 rows deleted.

ROLLBACK;
Rollback complete.

DELETE FROM test
WHERE id = 100;

1 row deleted.

SELECT *
FROM test
WHERE id = 100;
No rows selected.

COMMIT;
Commit complete

提交后我们无法回滚。

Rollback:

Discard all pending changes by using the ROLLBACK statement. Following a ROLLBACK statement:

  • Data changes are undone.
  • The previous state of the data is restored.
  • The locks on the affected rows are released.

Example

While attempting to remove a record from the TEST table, you can accidentally empty the table. You can correct the mistake, reissue the proper statement, and make the data change permanent.

DELETE FROM test;
25,000 rows deleted.

ROLLBACK;
Rollback complete.

DELETE FROM test
WHERE id = 100;

1 row deleted.

SELECT *
FROM test
WHERE id = 100;
No rows selected.

COMMIT;
Commit complete

After giving commit we can't rollback.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文