2017-11-23 3 views
0

Wie in Java gibt es schließlich Block, der unter allen Bedingungen ausgeführt wird.Ähnlich wie schließlich Block (JAVA) in Oracle PL/SQL-Block

Gibt es eine ähnliche Funktion in Oracle PL/SQL, die ausgeführt wird, wenn die Prozedur ihre Ausführung beendet, auch wenn eine Return-Anweisung verwendet wird?

+1

Im Gegensatz zu Java unterstützt PL/SQL keinen Abschnitt FINALLY. Sie können jedoch viel von dem, was dieser Abschnitt tut, emulieren. Überprüfen Sie diese http://www.oracle.com/technetwork/testcontent/o19plsql-085133.html und diese http://stevenfuersteinonplsql.blogspot.com/2017/01/emulating-finally-clause-in-plsql.html –

Antwort

0

Es gibt kein Äquivalent von FINALLY, aber Sie können es mit verschachtelten PL/SQL-Blöcken simulieren;

DECLARE 
    -- Your variables. 
    return_early BOOLEAN := FALSE; 
BEGIN 
    -- Do something 

    DECLARE 
    -- Local variables in "try" block 
    BEGIN 
    -- Equivalent of "try" block 
    -- Do something that may raise an exception 
    IF some_condition THEN 
     return_early := TRUE; 
     -- you could also use "GOTO end_try;" rather than surrounding the 
     -- following statements in an "ELSE" statement 
    ELSE 
     -- Do something else that may raise an exception 
    END IF; 
    EXCEPTION 
    WHEN your_exception THEN 
     -- Equivalent of "catch" block 
    END; 
    <<end_try>> 
    -- Handle "finally" here, after end of nested block. 
    -- Note: you can only see variables declared in this outer block 
    --  not variables local to the nested PL/SQL block. 
    IF return_early THEN 
    RETURN; 
    END IF; 

    -- Continue and do more stuff. 
END; 
/
Verwandte Themen