回滚命令不起作用 - Oracle
我删除了一个表并尝试回滚,但没有用。它会像这样工作还是我在这里玩错了?
从大多数评论来看,我清楚 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
我不相信回滚会撤消架构更改。
I don't believe rollback will undo schema changes.
没有保存点限定符的
ROLLBACK
将回滚整个当前事务。对于 DDL 语句,当前没有要回滚的事务。 DDL 语句在语句开始之前和完成之后隐式生成
COMMIT
。因此,如果您在DROP
之后发出ROLLBACK
,则当前事务中尚未完成任何工作,因此无需回滚。对于 DML 语句,您将回滚整个当前事务。如果您执行
那么您的事务将在您执行 INSERT 操作时开始。因此,当您发出
ROLLBACK
时,您将同时回滚INSERT
和DELETE
,因此表中将恢复为没有数据的状态(假设您开始时没有数据)。如果您在INSERT
之后COMMIT
,那么下一个事务将以DELETE
开始,并且您的ROLLBACK
只会回滚DELETE
操作。或者,您可以在INSERT
之后声明一个保存点并回滚到该保存点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 aROLLBACK
following aDROP
, 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
your transaction begins when you execute the
INSERT
operation. So when you issue theROLLBACK
, you are rolling back both theINSERT
and theDELETE
so you're back to having no data in the table (assuming you started with no data). If youCOMMIT
after theINSERT
then the next transaction would begin with theDELETE
and yourROLLBACK
will only roll back theDELETE
operation. Alternately, you can declare a savepoint after theINSERT
and roll back to the savepoint回滚不会撤消架构更改,但要撤消删除表操作,您可以检查:
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
来自文档:
这意味着您无法
ROLLBACK
DDL 语句(即架构更改)。From the documentation:
This means that you cannot
ROLLBACK
a DDL statement (that is, a schema change).回滚永远不会撤消数据定义命令,例如 drop table alter table 等。
Rollback will never undo Data Definition commands such as drop table alter table etc.
删除表会更改数据库的结构(使用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.
要回滚 ddl 更改,您需要使用 Flashback。
To rollback ddl changes you need to use Flashback.
回滚:
使用 ROLLBACK 语句放弃所有挂起的更改。 ROLLBACK 语句之后:
示例
当尝试从 TEST 表中删除记录时,您可能会意外清空该表。您可以更正错误,重新发出正确的语句,并使数据更改永久化。
提交后我们无法回滚。
Rollback:
Discard all pending changes by using the ROLLBACK statement. Following a ROLLBACK statement:
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.
After giving commit we can't rollback.