Lab-verifiedReproduced and fixed on Oracle AI Database 26ai Free 23.26.3.0.0 · 2026-11-30 · container image gvenzl/oracle-free:23-slim
A savepoint lives only inside the current transaction. Any COMMIT, explicit or implicit, ends the transaction and erases every savepoint, so a later ROLLBACK TO fails with ORA-01086. The message names the savepoint, e.g. savepoint 'BEFORE_SHIP', and in PL/SQL the ORA-06512 line points to the ROLLBACK TO line.
Below are three cases reproduced on Oracle 26ai Free with the fixes that were actually run.
01COMMIT between SAVEPOINT and ROLLBACK TO
The block set SAVEPOINT before_ship, updated the order to SHIPPED, wrote a log row, ran COMMIT, and then ROLLBACK TO before_ship. It failed with ORA-01086 at line 6.
The COMMIT had already saved the change: a check showed the order as SHIPPED. After resetting the order, the block was rewritten to ROLLBACK TO before_ship first and COMMIT after. It completed and the order stayed NEW.
Setup
CREATE TABLE orders (order_id NUMBER PRIMARY KEY, status VARCHAR2(10));
CREATE TABLE order_log (order_id NUMBER, msg VARCHAR2(50));
INSERT INTO orders VALUES (1, 'NEW');
COMMIT;Table created.
Table created.
1 row created.
Commit complete.BEGIN
SAVEPOINT before_ship;
UPDATE orders SET status = 'SHIPPED' WHERE order_id = 1;
INSERT INTO order_log VALUES (1, 'shipped');
COMMIT;
ROLLBACK TO before_ship;
END;
/BEGIN
*
ERROR at line 1:
ORA-01086: savepoint 'BEFORE_SHIP' never established in this session or is invalid
ORA-06512: at line 6
Help: https://docs.oracle.com/error-help/db/ora-01086/SELECT order_id, status FROM orders; ORDER_ID STATUS
---------- ------------------------------
1 SHIPPED
1 row selected.UPDATE orders SET status = 'NEW' WHERE order_id = 1;
COMMIT;1 row updated.
Commit complete.Move the COMMIT to after the point where you might roll back, or out of the block to the caller.
BEGIN
SAVEPOINT before_ship;
UPDATE orders SET status = 'SHIPPED' WHERE order_id = 1;
INSERT INTO order_log VALUES (1, 'shipped');
ROLLBACK TO before_ship;
COMMIT;
END;
/
SELECT order_id, status FROM orders;PL/SQL procedure successfully completed.
ORDER_ID STATUS
---------- ------------------------------
1 NEW
1 row selected.02DDL (TRUNCATE, CREATE ...) after SAVEPOINT
DDL commits implicitly. The block set SAVEPOINT before_batch, updated the order to DONE, ran EXECUTE IMMEDIATE 'TRUNCATE TABLE orders_work', and then ROLLBACK TO before_batch failed with ORA-01086 at line 5.
The TRUNCATE had committed the UPDATE (the order showed DONE). After resetting the data, the TRUNCATE was moved before SAVEPOINT. The block completed and ROLLBACK TO before_batch undid the update (status NEW).
Setup
CREATE TABLE orders (order_id NUMBER PRIMARY KEY, status VARCHAR2(10));
CREATE TABLE orders_work (order_id NUMBER, status VARCHAR2(10));
INSERT INTO orders VALUES (1, 'NEW');
COMMIT;Table created.
Table created.
1 row created.
Commit complete.BEGIN
SAVEPOINT before_batch;
UPDATE orders SET status = 'DONE' WHERE order_id = 1;
EXECUTE IMMEDIATE 'TRUNCATE TABLE orders_work';
ROLLBACK TO before_batch;
END;
/BEGIN
*
ERROR at line 1:
ORA-01086: savepoint 'BEFORE_BATCH' never established in this session or is invalid
ORA-06512: at line 5
Help: https://docs.oracle.com/error-help/db/ora-01086/SELECT order_id, status FROM orders; ORDER_ID STATUS
---------- ------------------------------
1 DONE
1 row selected.UPDATE orders SET status = 'NEW' WHERE order_id = 1;
COMMIT;1 row updated.
Commit complete.BEGIN
EXECUTE IMMEDIATE 'TRUNCATE TABLE orders_work';
SAVEPOINT before_batch;
UPDATE orders SET status = 'DONE' WHERE order_id = 1;
ROLLBACK TO before_batch;
END;
/
SELECT order_id, status FROM orders;PL/SQL procedure successfully completed.
ORDER_ID STATUS
---------- ------------------------------
1 NEW
1 row selected.03Wrong savepoint name
SAVEPOINT sp_stock was set, but ROLLBACK TO sp_stok was called. The message shows the name Oracle looked for: savepoint 'SP_STOK'. With the correct name, Rollback complete. and the qty stayed 10.
A check after the failed run showed qty 10: the script ended with ROLLBACK, so the UPDATE was not kept.
Setup
CREATE TABLE stock (item VARCHAR2(10), qty NUMBER);
INSERT INTO stock VALUES ('pen', 10);
COMMIT;Table created.
1 row created.
Commit complete.SAVEPOINT sp_stock;
UPDATE stock SET qty = qty - 3 WHERE item = 'pen';
ROLLBACK TO sp_stok;
ROLLBACK;Savepoint created.
1 row updated.
ROLLBACK TO sp_stok
*
ERROR at line 1:
ORA-01086: savepoint 'SP_STOK' never established in this session or is invalid
Help: https://docs.oracle.com/error-help/db/ora-01086/
Rollback complete.SELECT item, qty FROM stock;ITEM QTY
---------- ----------
pen 10
1 row selected.SAVEPOINT sp_stock;
UPDATE stock SET qty = qty - 3 WHERE item = 'pen';
ROLLBACK TO sp_stock;
SELECT item, qty FROM stock;Savepoint created.
1 row updated.
Rollback complete.
ITEM QTY
---------- ----------
pen 10
1 row selected.FAQ
What does savepoint never established in this session or is invalid mean?
The savepoint name does not exist in the current transaction. It was never set, has a different name, or was erased by a COMMIT (including the implicit COMMIT of DDL).
Does TRUNCATE inside PL/SQL remove savepoints?
Yes. TRUNCATE through EXECUTE IMMEDIATE commits, and the following ROLLBACK TO failed with ORA-01086. It also committed the UPDATE made before it.
Can I ROLLBACK TO a savepoint after COMMIT?
No. COMMIT ends the transaction and all its savepoints. Roll back to the savepoint first, then COMMIT.
How we verify
Each scenario starts from fresh database users. A script runs the setup, confirms the exact error code, applies the fix and runs the statement again. The output shown is what the database printed, saved by the script.
lab_a and lab_b are ordinary users created for the test; system is the DBA account. Oracle AI Database 26ai Free Release 23.26.3.0.0 - Develop, Learn, and Run for Free 23.26.3.0.0