2017-11-23 13 views
0

Java와 마찬가지로 모든 조건에서 실행되는 블록이 있습니다.Oracle PL/SQL 블록의 finally 블록 (JAVA)과 유사

return 문을 사용하더라도 프로 시저가 실행을 완료 할 때마다 실행되는 유사한 기능이 Oracle PL/SQL에 있습니까?

+1

Java와 달리 PL/SQL은 FINALLY 섹션을 지원하지 않습니다. 그러나이 섹션에서 수행하는 작업의 상당 부분을 에뮬레이션 할 수 있습니다. http://www.oracle.com/technetwork/testcontent/o19plsql-085133.html 및 http://stevenfeuersteinonplsql.blogspot.com/2017/01/emulation-finally-clause-in-plsql.html을 확인하십시오. –

답변

0

FINALLY에는 해당하지 않지만 중첩 된 PL/SQL 블록을 사용하여 시뮬레이션 할 수 있습니다.

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; 
/