小编Grz*_*orz的帖子

Oracle 11 - sqlplus - 在出错时回滚整个脚本 - 如何?

如何使 Oracle 11g 在包含的 SQL 文件中出现任何错误时回滚整个事务?

文件内容为:

set autocommit off
whenever SQLERROR EXIT ROLLBACK

insert into a values (1);
insert into a values (2);

drop index PK_NOT_EXIST;

commit;
Run Code Online (Sandbox Code Playgroud)

并且使用“@”将该文件包含到 sqlplus 会话中:

@error.sql
Run Code Online (Sandbox Code Playgroud)

正如预期的那样,sqlplus 会话终止,输出为

SQL> @error.sql
1 row created.
1 row created.
drop index PK_NOT_EXIST           *
ERROR at line 1:
ORA-01418: specified index does not exist
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
Run Code Online (Sandbox Code Playgroud)

但是当我重新启动 …

sqlplus rollback oracle11g

5
推荐指数
1
解决办法
2万
查看次数

标签 统计

oracle11g ×1

rollback ×1

sqlplus ×1