我正在尝试在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收到此错误


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

最佳答案

DDL语句(在这种情况下为ALTER TABLETRUNCATE TABLE)在执行之前和之后发出隐式提交。在执行第一个ALTER TABLE语句之前,已创建保存点的事务已结束。由于只能回滚到当前事务中定义的保存点,因此在发出DDL语句后不能回滚到该保存点。

关于sql - 保存点从未创建错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13485818/

10-09 09:08