我们如何通过使用execute子句重新创建TRG_1触发器,来指定在TRG_1触发器之前执行TRG_2触发器?

时间:2019-06-20 13:25:19

标签: oracle plsql

我创建了两个触发器,触发器1名称TRIGGER_FOLLOWS_TEST_TRG_2和触发器2名称TRIGGER_FOLLOWS_TEST_TRG_1

我希望通过重新创建TRIGGER_FOLLOWS_TEST_TRG_2触发器来在TRIGGER_FOLLOWS_TEST_TRG_1触发器之前执行TRIGGER_FOLLOWS_TEST_TRG_1触发器。

create or replace TRIGGER TRIGGER_FOLLOWS_TEST_TRG_1
AFTER INSERT OR UPDATE
OF ISSA_STATUS_P, PRB_BEW_CODE
ON PROBE
REFERENCING OLD AS OLD NEW AS NEW
FOR EACH ROW
EXECUTE TRIGGER_FOLLOWS_TEST_TRG_2
DECLARE
    V_STATUS VARCHAR2(10);
    V_BEW_CODE VARCHAR2(5);
BEGIN
    IF INSERTING OR UPDATING THEN
        V_STATUS := :NEW.ISSA_STATUS_P;
        V_BEW_CODE := :NEW.PRB_BEW_CODE;
    ELSE
        V_STATUS := :OLD.ISSA_STATUS_P;
        V_BEW_CODE := :OLD.PRB_BEW_CODE;
    END IF;

    IF (V_STATUS = 'PAF' AND V_BEW_CODE IS NULL) THEN
        RAISE_APPLICATION_ERROR (-20011, 'Error: Status is finalized but assessment code is null');
    END IF;

END TRIGGER_FOLLOWS_TEST_TRG_1;

create or replace TRIGGER TRIGGER_FOLLOWS_TEST_TRG_1
AFTER INSERT OR UPDATE
OF ISSA_STATUS_P, PRB_BEW_CODE
ON PROBE
DEFERRABLE INITIALLY DEFERRED
REFERENCING OLD AS OLD NEW AS NEW
FOR EACH ROW
EXECUTE TRIGGER_FOLLOWS_TEST_TRG_2
DECLARE
    V_STATUS VARCHAR2(10);
    V_BEW_CODE VARCHAR2(5);
BEGIN
    IF INSERTING OR UPDATING THEN
        V_STATUS := :NEW.ISSA_STATUS_P;
        V_BEW_CODE := :NEW.PRB_BEW_CODE;
    ELSE
        V_STATUS := :OLD.ISSA_STATUS_P;
        V_BEW_CODE := :OLD.PRB_BEW_CODE;
    END IF;

    IF (V_STATUS = 'PAF' AND V_BEW_CODE IS NULL) THEN
        RAISE_APPLICATION_ERROR (-20011, 'Error: Status is finalized but assessment code is null');
    END IF;

END TRIGGER_FOLLOWS_TEST_TRG_1;

我已经尝试过了:

create or replace TRIGGER TRIGGER_FOLLOWS_TEST_TRG_1
AFTER INSERT OR UPDATE
OF ISSA_STATUS_P, PRB_BEW_CODE
ON PROBE
REFERENCING OLD AS OLD NEW AS NEW
FOR EACH ROW
EXECUTE TRIGGER_FOLLOWS_TEST_TRG_2
DECLARE
    V_STATUS VARCHAR2(10);
    V_BEW_CODE VARCHAR2(5);
BEGIN
    IF INSERTING OR UPDATING THEN
        V_STATUS := :NEW.ISSA_STATUS_P;
        V_BEW_CODE := :NEW.PRB_BEW_CODE;
    ELSE
        V_STATUS := :OLD.ISSA_STATUS_P;
        V_BEW_CODE := :OLD.PRB_BEW_CODE;
    END IF;

    IF (V_STATUS = 'PAF' AND V_BEW_CODE IS NULL) THEN
        RAISE_APPLICATION_ERROR (-20011, 'Error: Status is finalized but assessment code is null');
    END IF;

END TRIGGER_FOLLOWS_TEST_TRG_1;

创建此触发器时,它在“ EXECUTE”附近显示错误。

0 个答案:

没有答案