【发布时间】:2018-10-14 02:51:21
【问题描述】:
我有两个表,这里涉及两个不同的模式。
架构服务和表任务 -- 列 ID
schme mona_internal 和 table officius_unos -- 列任务
在列任务表 officius_unos 中插入时我需要触发器来检查表任务中列 id 中是否存在插入值。如果存在则继续插入,不存在则报错。
这里是触发器:
CREATE OR REPLACE TRIGGER mona_internal.PROBA_PROBA
BEFORE INSERT ON OFFICIUS_UNOS
FOR EACH ROW
DECLARE
task_provera number(10);
BEGIN
select id into task_provera from servis.task
where id=:new.task;
if (task_provera is null)
then raise_application_error(-20101, 'No task');
else insert into mona_internal.OFFICIUS_UNOS (task) values (:new.task);
end if;
END;
触发器已编译,但尝试在列任务表officius_unos中插入新值时出现问题, 它返回给我这条消息
insert into officius_unos (task) values (291504);
Error report -
ORA-00036: maximum number of recursive SQL levels (50) exceeded
ORA-00036: maximum number of recursive SQL levels (50) exceeded
ORA-06512: at "MONA_INTERNAL.PROBA_PROBA", line 5
ORA-04088: error during execution of trigger 'MONA_INTERNAL.PROBA_PROBA'
ORA-06512: at "MONA_INTERNAL.PROBA_PROBA", line 10
并且值 291504 存在于表任务的列 id 中。
附:也尝试用检查约束来解决这个问题,但是有禁止的子查询。我用来克服我的问题的解决方案在这里
【问题讨论】:
-
else insert into mona_internal.OFFICIUS_UNOS (task) values (:new.task);不是必需的。这就是错误的原因 -
为什么不使用外键约束呢?