DBILITY

oracle procedure dml시 lock 확인 후 오류처리 본문

database/oracle

oracle procedure dml시 lock 확인 후 오류처리

DBILITY 2016. 9. 27. 11:53
반응형
CREATE OR REPLACE PROCEDURE TEST_FILTER_INSERT (V_MSG out VARCHAR2) IS
START_TIME  NUMBER;
END_TIME    NUMBER;
TX_CNT NUMBER;
TX_INPROGRESS EXCEPTION;
/******************************************************************************
   NAME:       TEST_FILTER_INSERT
   PURPOSE:    테스트

   REVISIONS:
   Ver        Date        Author           Description
   ---------  ----------  ---------------  ------------------------------------
   1.0        2016/09/27   ROOKIE       1. Created this procedure.
******************************************************************************/
BEGIN

    START_TIME := DBMS_UTILITY.GET_TIME;
   
       
    V_MSG := 'TEST_FILTER_INSERT ';
    
    SELECT 
        COUNT(*) INTO TX_CNT 
    FROM 
        V$SESSION A, V$LOCK B, DBA_OBJECTS C
    WHERE     A.SID = B.SID
       AND B.ID1 = C.OBJECT_ID
       AND B.TYPE = 'TM'
       AND C.OWNER = '소유자'
       AND C.OBJECT_NAME = '테이블';
       
    IF ( TX_CNT > 0 ) THEN
        RAISE TX_INPROGRESS;
    END IF;
    
   /* DML
    * DELETE FROM 테이블 WHERE 컬럼='999999';
    */
                          
    END_TIME := DBMS_UTILITY.GET_TIME;
           
    V_MSG := V_MSG||' ELAPSED: '||TO_CHAR( (END_TIME-START_TIME)/100,'FM9,990.990')||' ,Rows affected : '||TO_CHAR(SQL%ROWCOUNT,'FM999,999,990');
       
    COMMIT;
       
    EXCEPTION
     WHEN NO_DATA_FOUND THEN
       NULL;
     WHEN TX_INPROGRESS THEN
       ROLLBACK;
       --RAISE_APPLICATION_ERROR(-20001,'이미 실행중입니다.');
       V_MSG := V_MSG||' ERROR: 이미 실행중입니다.';   
     WHEN OTHERS THEN
       ROLLBACK;
       V_MSG := V_MSG||' ERROR: '||SQLERRM;
       --DBMS_OUTPUT.PUT_LINE(V_MSG);
       RAISE;
END TEST_FILTER_INSERT;
/
반응형
Comments