中止 PL/SQL 程序 [英] Abort a PL/SQL program
本文介绍了中止 PL/SQL 程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何让 PL/SQL 程序中途结束?如果发生异常,我无法找到任何方法来优雅地结束程序 - 如果我处理它,它会循环回到代码中.
How do I get a PL/SQL program to end halfway through? I haven't been able to find any way to gracefully end the program if an exception occurs - if I handle it, it loops back into the code.
基本上我想做的是强制应用程序不在某些条件下运行.所以,我想在程序的顶部添加这样的东西:
Basically what I want to do is force the app not to run in certain conditions. So, I want to add something like this to the top of the program:
BEGIN
IF [condition]
EXIT
END IF
[the rest of the program]
END
建议的方法是抛出异常,但块很可能是内部块 - 所以块外的程序会继续运行.
The suggested way is to throw an exception, but the block may well be an inner block - so the program outside of the block just keeps going.
推荐答案
可以使用 RETURN
You can use RETURN
MWATSON@> set serveroutput on
MWATSON@> !cat test.sql
BEGIN
IF 1 = 1 THEN
DBMS_OUTPUT.PUT_LINE('ABOUT TO EXIT');
RETURN;
END IF;
DBMS_OUTPUT.PUT_LINE('DID NOT EXIT');
END;
MWATSON@> @test
8 /
ABOUT TO EXIT
PL/SQL procedure successfully completed.
MWATSON@>
这篇关于中止 PL/SQL 程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文