Question

I'm trying to create a savepoint in 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;

But I keep getting this error from SQL Developer

ROLLBACK TO SAVEPOINT1 Error report: SQL Error: ORA-01086: savepoint 'SAVEPOINT1' never established in this session or is invalid 01086. 00000 - "savepoint '%s' never established" *Cause: Trying to roll back to a save point that was never established. *Action:

Was it helpful?

Solution

DDL statements-- ALTER TABLE and TRUNCATE TABLE in this case-- issue implicit commits before and after they are executed. The transaction that the savepoint was created in was ended before the first ALTER TABLE statement was executed. Since you can only rollback to a savepoint defined in the current transaction, you cannot rollback to the savepoint after issuing DDL statements.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top