我正在尝试在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'从未建立过” *原因:尝试回滚到从未建立的保存点。 *操作:
答案 0 :(得分:6)
DDL
语句 - ALTER TABLE
和TRUNCATE TABLE
- 在执行它们之前和之后发出隐式提交。创建保存点的事务在执行第一个ALTER TABLE
语句之前结束。由于您只能回滚到当前事务中定义的保存点,因此在发出DDL
语句后无法回滚到保存点。