develog

trigger 본문

DB/Oracle

trigger

냐옴 2013. 2. 8. 13:27
--트리거 생성

CREATE OR REPLACE TRIGGER ATEST_TRIGGER

BEFORE INSERT OR UPDATE OR DELETE ON ATEST

REFERENCING OLD AS O NEW AS N

FOR EACH ROW

DECLARE


BEGIN


    IF INSERTING THEN

        INSERT INTO ATEST_LOG

            (SEQ, TITLE, NOTE, USE_YN, REG_TS, MOD_TS, LOG_TS, LOG_TYPE)

        VALUES

            (:O.SEQ, :O.TITLE, :O.NOTE, :O.USE_YN, :O.REG_TS, :O.MOD_TS, SYSTIMESTAMP, 'I');

    END IF;


    IF UPDATING THEN

        INSERT INTO ATEST_LOG

            (SEQ, TITLE, NOTE, USE_YN, REG_TS, MOD_TS, LOG_TS, LOG_TYPE)

        VALUES

            (:O.SEQ, :O.TITLE, :O.NOTE, :O.USE_YN, :O.REG_TS, :O.MOD_TS, SYSTIMESTAMP, 'U');

    END IF;



    IF DELETING THEN

        INSERT INTO ATEST_LOG

            (SEQ, TITLE, NOTE, USE_YN, REG_TS, MOD_TS, LOG_TS, LOG_TYPE)

        VALUES

            (:O.SEQ, :O.TITLE, :O.NOTE, :O.USE_YN, :O.REG_TS, :O.MOD_TS, SYSTIMESTAMP, 'D');

    END IF;


END;


--트리거 삭제

DROP TRIGGER ATEST_TRIGGER;


--트리거 활성
ALTER TRIGGER ATEST_TRIGGER ENABLE;

--트리거 비활성
ALTER TRIGGER ATEST_TRIGGER DISABLE;

'DB > Oracle' 카테고리의 다른 글

Function  (0) 2013.02.12
[Oracle] CREATE INDEX  (0) 2013.02.08
WMSYS.WM_CONCAT  (0) 2013.01.10
plsql default parameter  (0) 2012.12.13
Pseudo Columns  (0) 2012.12.12
Comments