Exception handling 在pl sql中的所有异常情况下,是否都要执行某些操作?
我想在发生异常时为变量赋值Exception handling 在pl sql中的所有异常情况下,是否都要执行某些操作?,exception-handling,plsql,Exception Handling,Plsql,我想在发生异常时为变量赋值 exception when excep1 then var = true; when excep2 then var = true; end; 我想做点什么,可能吗 exception var = true; when excep1 then -- do something when excep2 then -- do something end; 可以使用子块执行此操作,首先设置值,然后重新引发异常以处
exception
when excep1 then
var = true;
when excep2 then
var = true;
end;
我想做点什么,可能吗
exception
var = true;
when excep1 then
-- do something
when excep2 then
-- do something
end;
可以使用子块执行此操作,首先设置值,然后重新引发异常以处理它:
begin
begin
-- do something
exception
when others then
var = true;
raise; -- re-raise the current exception for further exception handling
end;
exception
when excep1 then
-- do something
when excep2 then
-- do something
end;
按照Odi的建议重新筹集资金肯定会奏效。你通过做一些不同的事情得到同样的效果
begin
var := true;
... your code that can cause exceptions...
var := false; --var set to false unless an exception was encountered
exception
when exception1 then
...
when exception2 then
...
end;
另一种方法是将其放入另一个程序中,例如:
declare
procedure common_exception_routine is
begin
var = true;
end common_exception_routine;
begin
...
exception
when excep1 then
common_exception_routine;
when excep2 then
common_exception_routine;
end;
谢谢约翰,真的很棒。谢谢你的回复,奥迪:)