我想创建一个'而不是删除'触发器,以便在输入的值超过一定数量时限制删除行。
我有一个包含2列的发票表:发票(发票号码,总数)
如果我尝试删除总计> = 100中存储值的行并且阻止删除,我希望触发器触发。
到目前为止,我已经粗略地描述了我想要的内容,但我不确定确切的语法是否正确。
CREATE OR REPLACE TRIGGER IOFD_INVOICE
INSTEAD OF DELETE ON INVOICE
BEGIN
DECLARE
TTL INTEGER;
SELECT TOTAL = TTL
FROM INVOICE
IF TTL >= 100
BEGIN
RAISERROR('Record cannot be deleted.')
ROLLBACK
END
ELSE
BEGIN
DELETE FROM INVOICE
END
END;
我认为可以在表上使用而不是触发器但是我收到以下错误消息:
Error report -
ORA-25002: cannot create INSTEAD OF triggers on tables
25002. 00000 - "cannot create INSTEAD OF triggers on tables"
*Cause: Only BEFORE or AFTER triggers can be created on a table.
*Action: Change the trigger type to BEFORE or AFTER.
答案 0 :(得分:2)
INSTEAD OF触发器仅适用于视图。
逻辑可以通过简单的
来完成CREATE OR REPLACE TRIGGER BD_INVOICE
BEFORE DELETE ON INVOICE FOR EACH ROW
BEGIN
IF :OLD.TOTAL >= 100 THEN
RAISE_APPLICATION_ERROR(-20001,'Record cannot be deleted.');
END IF;
END;