单个“ when”子句可以在oracle中处理多种异常类型吗?

Pab*_*iva 4 oracle exception-handling exception

假设我有一个过程如下:

PROCEDURE proc_name (args)
IS

  --  declarations
    ...
BEGIN

    -- code
    ...
EXCEPTION

    WHEN an_error THEN

        --error handling code
         ....
        WHEN another_error THEN

        -- error handling code, identical to the one for an_error
         ...
     WHEN others THEN
       ---generic error handling code`
       ....
END;
Run Code Online (Sandbox Code Playgroud)

理想情况下,我希望能够赶上这两个an_erroranother_error在同一个WHEN子句,因为它们的处理是相同的。

在Oracle中这可能吗?如果没有,还有什么其他可能性可以避免代码重复?

Sen*_*nel 5

是的你可以。

您可以在例外之间使用OR条件,以便

EXCEPTION
  WHEN an_exception 
    OR another_exception
  THEN
    handle it here;
END;
Run Code Online (Sandbox Code Playgroud)

有关异常处理的更多详细信息,请参见文档