我正在尝试创建一个触发器,当用户插入表时,触发器将与另一个表连接并插入到主表中。这是我到目前为止创建的触发器。当我将它插入数据库时,我得到“警告:使用编译错误创建的触发器”。
CREATE OR REPLACE TRIGGER TBI_PERSONS_IDM_STAGING
AFTER INSERT
ON PERSONS_IDM_STAGING
FOR EACH ROW
BEGIN
IF :new.PERSON NOT IN (SELECT PERSON FROM PERSONS) AND INSERTING
THEN
INSERT INTO PERSONS (
PERSON,
DBLOGIN_ID,
LAST_NAME,
FIRST_NAME,
DEPARTMENT,
JOBTITLE,
USERLEVEL,
FACILITY_ID,
USER_OPTIONS,
PASSWORD)
VALUES(:new.PERSON,
:new.PERSON,
:new.LAST_NAME,
:new.FIRST_NAME,
:new.DEPARTMENT,
:new.JOBTITLE,
:new.USERLEVEL,
(SELECT KMS_FACILITY_ID FROM FACILITY_IDM_STAGING WHERE FACILITY_IDM_STAGING.IDM_CODE = :new.IDM_CODE),
:new.USER_OPTIONS,
:new.PASSWORD);
END IF;
END;
/
谁能看到我做错了什么?
更新:我能够修复代码。如果其他人有此问题,这是正确的陈述:
CREATE OR REPLACE TRIGGER TAI_PERSONS_IDM_STAGING
AFTER INSERT
ON PERSONS_IDM_STAGING
FOR EACH ROW
BEGIN
INSERT INTO PERSONS (
PERSON,
DBLOGIN_ID,
LAST_NAME,
FIRST_NAME,
DEPARTMENT,
JOBTITLE,
USERLEVEL,
FACILITY_ID,
USER_OPTIONS,
PASSWORD)
VALUES(:new.PERSON,
:new.PERSON,
:new.LAST_NAME,
:new.FIRST_NAME,
:new.DEPARTMENT,
:new.JOBTITLE,
:new.USERLEVEL,
(SELECT KMS_FACILITY_ID FROM FACILITY_IDM_STAGING WHERE FACILITY_IDM_STAGING.IDM_CODE = :new.IDM_CODE),
:new.USER_OPTIONS,
:new.PASSWORD);
EXCEPTION
WHEN DUP_VAL_ON_INDEX THEN NULL;
END;
/