Oracle Trigger on Nested Table

拟墨画扇 提交于 2019-12-12 01:07:10

问题


I want to create a trigger to validate the date of birth, for example it's not > SYSDATE:

Employee -- STRUCTURED TYPE
{
     name VARCHAR2(10)
     lastname VARCHAR(10)
     birthdate DATE
}

Employee_List TABLE OF Employee -- NESTED TABLE

Museum -- TABLE
{
     id NUMBER
     EmployeeList Employee_List
}

I'm using Oracle 10g.


回答1:


You cannot define a trigger like "BEFORE UPDATE ON Museum.EmployeeList.birthdate" But you can write a normal trigger BEFORE UPDATE ON Museum and in trigger body you can loop over all employees checking the date.

Try this one:

CREATE OR REPLACE TRIGGER BUIR_Museum 
    BEFORE INSERT OR UPDATE ON Museum
    FOR EACH ROW

BEGIN
    IF :NEW.EmployeeList IS NOT NULL THEN
        FOR i IN :NEW.EmployeeList.FIRST..:NEW.EmployeeList.LAST LOOP
            IF :NEW.EmployeeList(i).birthdate > SYSDATE THEN
                RAISE_APPLICATION_ERROR(-20029, 'Invalid birthday');
            END IF;
        END LOOP;
    END IF;
END;


来源:https://stackoverflow.com/questions/20232794/oracle-trigger-on-nested-table

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!