gpt4 book ai didi

oracle - 类似于 Oracle PL/SQL block 中的 finally Block (JAVA)

转载 作者:行者123 更新时间:2023-12-02 09:15:39 27 4
gpt4 key购买 nike

在 Java 中,finally block 在所有条件下都执行。

Oracle PL/SQL 中是否有任何类似的函数,只要过程完成执行,即使使用了 return 语句也会执行?

最佳答案

FINALLY 没有等价物,但您可以使用嵌套的 PL/SQL block 来模拟它;

DECLARE
-- Your variables.
return_early BOOLEAN := FALSE;
BEGIN
-- Do something

DECLARE
-- Local variables in "try" block
BEGIN
-- Equivalent of "try" block
-- Do something that may raise an exception
IF some_condition THEN
return_early := TRUE;
-- you could also use "GOTO end_try;" rather than surrounding the
-- following statements in an "ELSE" statement
ELSE
-- Do something else that may raise an exception
END IF;
EXCEPTION
WHEN your_exception THEN
-- Equivalent of "catch" block
END;
<<end_try>>
-- Handle "finally" here, after end of nested block.
-- Note: you can only see variables declared in this outer block
-- not variables local to the nested PL/SQL block.
IF return_early THEN
RETURN;
END IF;

-- Continue and do more stuff.
END;
/

关于oracle - 类似于 Oracle PL/SQL block 中的 finally Block (JAVA),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47449888/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com