我尝试创建一个触发器以防止在 SQL Developer (Oracle 11g XPRESS) 中插入重复条目,但它没有正确编译。你能帮我解释为什么,因为我看不到任何明显的语法错误。
CREATE OR REPLACE TRIGGER trig1
BEFORE INSERT ON table1
BEGIN
DECLARE CURSOR C1
IS
SELECT value1,value2 FROM inserted;
DECLARE value11 number;
DECLARE value22 number;
OPEN C1;
FETCH NEXT FROM C1 INTO @value11, @value22;
WHILE FETCH_STATUS = 0
LOOP
IF NOT EXISTS (SELECT * FROM table1 WHERE value1 = @value11 AND value2 = @value22)
THEN
INSERT INTO table1 (value1,value2)
VALUES
(@value11, @value22);
ELSE
ROLLBACK TRANSACTION
--DELETE FROM table1 WHERE value1 = @value11 AND value2 = @value22
PRINT 'Cannot add duplicate entry.'
END IF;
FETCH NEXT FROM C1 INTO @value11, @value22;
END LOOP;
CLOSE C1;
END;