为什么你会在这种情况下引发异常?你应该只在两种情况下真的发生异常:
- 你打算捕获异常并在调用代码中正确处理它。
- 有些东西是错的,你想让你的应用程序崩溃和烧伤。
你不是在做这些事情,也不需要。你只是想停止代码运行和“返回”(这是一个过程)你的价值。在这种情况下,我会建议使用return
。
return
结束包含它的匿名块的执行,并在过程中将“控制”返回给调用语句。即它完美地符合法案。
在停止执行过程之前,使用return,以下代码将sdate
指定给out
参数。 “更多的东西”永远不会发生。
create or replace procedure my_procedure_one (returnval in out date) is
begin
-- some stuff.
if sdate > sysdate then
returnval := sdate;
-- we don-t want to continue any more if this is true.
return;
end if;
-- more stuff.
end;
如果你只是想分配给sdate
如果returnval
的条件是不真,那么你只需换轮这两条线;也许可以将它从if语句中删除,以使其更加明显。这就是你的代码目前所做的,因为当你提升exec_not_allowed
时,所有执行都停止了。
create or replace procedure my_procedure_two (returnval in out date) is
begin
-- some stuff.
-- we don-t want to continue any more if this is true.
if sdate > sysdate then
return;
end if;
returnval := sdate;
-- more stuff.
end;
无论哪种情况,您的Java调用都保持不变。在第一个程序(my_procedure_one
)中,您将获得sdate
个返回,并在第二个过程中返回null,假定returnval
以前未被分配。
来源
2012-06-07 16:55:03
Ben
是不是'returnval:= sdate'在任何情况下都无法访问? – beerbajay
@beerbajay我在编译和运行过程时没有遇到任何此类错误。 – user75ponic