最大递归SQL级别数

时间:2012-03-30 14:54:21

标签: oracle triggers

    java.sql.SQLException: ORA-00036: maximum number of recursive SQL levels (50) exceeded ORA-06512: at "EPOLICIA.EMER_COMPLAINT_VALIDATE", 
line 5 ORA-04088: error during execution of trigger 'EPOLICIA.EMER_COMPLAINT_VALIDATE' ORA-06512: at "EPOLICIA.EMER_COMPLAINT_VALIDATE", 
line 5 ORA-04088: error during execution of trigger 'EPOLICIA.EMER_COMPLAINT_VALIDATE' ORA-06512: at "EPOLICIA.EMER_COMPLAINT_VALIDATE", 
line 5 ORA-04088: error during execution of trigger 'EPOLICIA.EMER_COMPLAINT_VALIDATE' ORA-06512: at "EPOLICIA.EMER_COMPLAINT_VALIDATE", 
line 5 ORA-04088: error during execution of trigger 'EPOLICIA.EMER_COMPLAINT_VALIDATE' ORA-06512: at "EPOLICIA.EMER_COMPLAINT_VALIDATE", 
line 5 ORA-04088: error during execution of trigger 'EPOLICIA.EMER_COMPLAINT_VALIDATE' ORA-06512: at "EPOLICIA.EMER_COMPLAINT_VALIDATE", 
line 5 ORA-04088: error during execution of trigger 'EPOLICIA.EMER_COMPLAINT_VALIDATE' ORA-06512: at "EPOLICIA.EMER_COMPLAINT_VALIDATE", 
line 5 ORA-04088: error during execution of trigger 'EPOLICIA.EMER_COMPLAINT_VALIDATE' ORA-06512: at "EPOLICIA.EMER_COMPLAINT_VALIDATE", 
line 5 ORA-04088: error during execution of trigger 'EPOLICIA.EMER_COMPLAINT_VALIDATE' ORA-06512: at "EPOLICIA.EMER_COMPLAINT_VALIDATE", 
line 5 ORA-04088: error during execution of trigger 'EPOLICIA.EMER_COMPLAINT_VALIDATE' ORA-06512: at "EPOLICIA.EMER_COMPLAINT_VALIDATE", 
line 5 ORA-04088: error during execution of trigger 'EPOLICIA.EMER_COMPLAINT_VALIDATE' ORA-06512: at "EPOLICIA.EMER_COMPLAINT_VALIDATE", 
line 5 ORA-04088: error during execution of trigger 'EPOLICIA.EMER_COMPLAINT_VALIDATE' ORA-06512: at "EPOLICIA.EMER_COMPLAINT_VALIDATE", 
line 5 ORA-04088: error during execution of trigger 'EPOLICIA.EMER_COMPLAINT_VALIDATE' ORA-06512: at "EPOLICIA.EMER_COMPLAINT_VALIDATE", 
line 5 ORA-04088: error during execution of trigger 'EPOLICIA.EMER_COMPLAINT_VALIDATE' ORA-06512: at "EPOLICIA.EMER_COMPLAINT_VALIDATE", 
line 5 ORA-04088: error during execution of trigger 'EPOLICIA.EMER_COMPLAINT_VALIDATE' ORA-06512: at "EPOLICIA.EMER_COMPLAINT_VALIDATE", 
line 5 ORA-04

我创建了一个触发器,通过该触发器,我将限制用户在一天内仅接受来自特定IP地址的一个投诉

EMER_COMPLAINT_VALIDATE

create or replace trigger emer_complaint_validate before insert on emer_complaint for each row
begin
if(((:new.date_time) = (:old.date_time)) AND ((:new.ip_add) = (:old.ip_add))) then
RAISE_APPLICATION_ERROR(-20001, 'Only one complaint accepted !!'); 
ELSE
insert into emer_complaint values(:new.case_id,:new.complaint,:new.land_mark,:new.station_id,:new.date_time,:new.ip_add,:new.status);
end if;
end;
/

表的结构,已应用触发器 EMER_COMPLAINT

1 个答案:

答案 0 :(得分:3)

您需要的是约束,而不是触发器。在11g:

ALTER TABLE emer_complaint 
   ADD (date_complaint DATE GENERATED ALWAYS AS (trunc(date_time)));

ALTER TABLE emer_complaint 
   ADD CONSTRAINT "one complaint per day" UNIQUE (ip_add, date_complaint);

在10g及之前:

CREATE UNIQUE INDEX "one complaint per day" 
   ON emer_complaint (ip_add, trunc(date_time));

Don't use triggers for (cross-row) integrity

相关问题