小编Dav*_*cum的帖子

在PL/SQL中引发错误后返回函数是最佳做法

我在包中有一堆函数,首先检查所请求工作的有效性,如果没有则抛出异常.

例:

package body foo as
  function implode (
    i_foo_id number
  ) return implode_id as
    not_implodable exception;
    implode_id number;
  begin
    if not is_implodable(i_foo_id) then
      raise not_implodable;
    end if;
    //Implode logic here.
    return implode_id;
  exception
    when not_implodable then
      raise_application_error(-20005, 'Imploding is not possible on this foo.');
  end implode;
end foo;
Run Code Online (Sandbox Code Playgroud)

我打开了警告报告并在编译时得到类似的内容.

警告(67,3):PLW-05005:子程序IMPLODE在第14行返回无值.

如果我在raise_application_error之后放置一个return语句,那么警告就会消失.由于提出错误会退出调用堆栈,还是有任何理由返回null吗?

oracle plsql

9
推荐指数
1
解决办法
6692
查看次数

标签 统计

oracle ×1

plsql ×1