保存点永远不会创建错误

时间:2012-11-21 03:19:47

标签: sql windows-7 oracle11g savepoints

我正在尝试在Oracle 11g中创建一个保存点。

ALTER TABLE ORDERS
DISABLE CONSTRAINT ORDERS_C_ID_FK;

DELETE FROM CUSTOMER;

SELECT * FROM CUSTOMER;

ROLLBACK;

SELECT * FROM CUSTOMER;

SAVEPOINT SAVEPOINT1;

ALTER TABLE ORDERS
DISABLE CONSTRAINT ORDERS_OS_ID_FK;

ALTER TABLE ORDER_LINE
DISABLE CONSTRAINT ORDER_LINE_O_ID_FK;

TRUNCATE TABLE CUSTOMER;
TRUNCATE TABLE ORDER_SOURCE;
TRUNCATE TABLE ORDERS;
DELETE FROM ORDERS;

ROLLBACK TO SAVEPOINT1;

但是我一直从SQL Developer

中得到这个错误
  

ROLLBACK TO SAVEPOINT1错误报告:SQL错误:ORA-01086:savepoint   'SAVEPOINT1'从未在此会话中建立或无效   01086. 00000 - “保存点'%s'从未建立过”   *原因:尝试回滚到从未建立的保存点。   *操作:

1 个答案:

答案 0 :(得分:6)

在这种情况下,

DDL语句 - ALTER TABLETRUNCATE TABLE - 在执行它们之前和之后发出隐式提交。创建保存点的事务在执行第一个ALTER TABLE语句之前结束。由于您只能回滚到当前事务中定义的保存点,因此在发出DDL语句后无法回滚到保存点。