且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用触发器更改插入的值

更新时间:2023-02-05 07:39:24

在Oracle的触发器语法中,新插入的记录由:new而不是new引用(请注意冒号).另外,SET是更新语句的一部分,而不是设置字段值的方法-这些是通过简单的赋值完成的,但是请注意,这些是通过:=而不是=完成的.
因此,您的触发器应显示为:

In Oracle's trigger syntax the newly inserted record is referred to by :new, not new (notice the colon). Additionally, SET is a part of an update statement, not a way to set field values - those are done by simple assignments, but note that these are done with := rather than =.
So, your trigger should read:

CREATE OR REPLACE TRIGGER NumberOfBooks
    BEFORE INSERT
    ON book
    FOR EACH ROW
BEGIN
    IF :new.nobook < 10
    THEN
        :new.nobook := 10;
    END IF;
END;