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

Taj*_*der 3 oracle plsql oracle11g

在 Java 中,有一个在所有条件下都执行的 finally 块。

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

MT0*_*MT0 5

没有等效的,FINALLY但您可以使用嵌套的 PL/SQL 块模拟它;

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;
/
Run Code Online (Sandbox Code Playgroud)