2012-04-10 5 views
1

例外が発生したときに変数に値を代入したい。pl SQLのすべての例外ケースで何かを実行する方法はありますか?

exception 
    when excep1 then 
    var = true; 
    when excep2 then 
    var = true; 
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; 

答えて

3

再調達をODIは間違いなくうまくいく提案されているよう:

exception 
    var = true; 
    when excep1 then 
    -- do something 
    when excep2 then 
    -- do something 
end; 
+0

おかげでジョン、それは本当に素晴らしいことです。 – Vaandu

1

あなたが最初の値を設定し、それを処理するために例外を再引き上げ、サブブロックでこれを行うことができます。あなたは、少し違ったやり方で同じ効果を得ます。

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; 
+0

感謝:) – Vaandu

1

もう一つの方法は、例えば、別の手順でそれを置くことです。:あなたの応答、ODIのため

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; 
+0

ありがとうございますJeffrey :) – Vaandu

関連する問題