在一个sql文件中编写的原始触发器:
CREATE OR REPLACE TRIGGER "LOCATION_TRIGGER"
BEFORE INSERT ON BBT_LOCATIONS
FOR EACH ROW
BEGIN
IF :new.LOCATIONID < 1000
THEN :new.LOCATIONID := :new.LOCATIONID;
ELSE
:new.LOCATIONID := LOCATIONID_SEQ.NEXTVAL;
END IF;
END LOCATION_TRIGGER;
---------------------------------------
CREATE OR REPLACE TRIGGER "ROUTESTOP_TRIGGER"
BEFORE INSERT ON BBT_ROUTESTOP
FOR EACH ROW
DECLARE
matches varchar2(4);
BEGIN
SELECT COUNT(*) INTO matches FROM BBT_LOCATIONS WHERE LOCATIONID = :new.STOP_REFERENCE;
IF (match <> 1)
THEN
SELECT LOCATIONID into :new.STOP_REFERENCE
FROM BBT_LOCATIONS
WHERE NAME = :new.NAME;
END IF;
END ROUTESTOP_TRIGGER;
当运行时,两个触发器的所有代码都进入LOCATION_TRIGGER,而所有进入ROUTESTOP_TRIGGER的代码都是
create or replace
第一次写入触发器。觉得我的语法一定是错的,但我看不到它。提前谢谢。
答案 0 :(得分:1)
您可以尝试在每次触发后在新行上添加正斜杠以在缓冲区中执行命令:
CREATE OR REPLACE TRIGGER "LOCATION_TRIGGER"
.......
END LOCATION_TRIGGER;
/
答案 1 :(得分:0)
不应该这样,
IF (matches <> 1) instead of IF (match <> 1) in the code?
声明的变量是
matches varchar2(4); but you are using match inside
这将通过错误。