【发布时间】:2018-04-26 07:58:05
【问题描述】:
有人知道,为什么我在以下代码中得到一个ORA-01086: savepoint 'SPX' never established in this session or is invalid?
begin
rollback; --clear all Transactions
execute immediate 'begin
savepoint SPX;
raise no_data_found;
end;';
exception when no_data_found then
rollback to savepoint SPX;
end;
如果我不使用立即执行,它就可以工作:
begin
rollback; --clear all Transactions
begin
savepoint SPX;
raise no_data_found;
end;
exception when no_data_found then
rollback to savepoint SPX;
end;
这是预期的行为还是类似于错误?
我正在使用Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
更新: 以下示例也可以使用,它使用动态 SQL 与 Savepoints 相结合:
begin
rollback; --clear all Transactions
execute immediate 'begin
savepoint SPX;
end;';
rollback to savepoint SPX;
end;
【问题讨论】:
标签: oracle plsql dynamic-sql