有没有办法在出错时回滚并退出psql脚本?

dtc*_*dtc 4 oracle plsql

我有一个psql脚本,如下所示:

-- first set of statements
begin
sql statement;
sql statement;
sql statement;
exception
    when others then
    rollback
    write some output
    (here I want to exit the entire script and not continue on to the next set of statements)
end
/
-- another set of statements
begin
sql statement;
sql statement;
sql statement;
exception
    when others then
    rollback
    write some output
    (here I want to exit the entire script and not continue)
end
/
... and so on
Run Code Online (Sandbox Code Playgroud)

是否可以退出脚本并停止处理脚本的其余部分?

Vad*_* K. 7

将以下行放在文件的顶部:

WHENEVER OSERROR EXIT ROLLBACK
WHENEVER SQLERROR EXIT ROLLBACK
Run Code Online (Sandbox Code Playgroud)

...并确保RAISE;在异常处理程序的末尾有一个.