我正在尝试在 firebird 2.5 上创建一个触发器,以便在更新另一列时更新一列。我为我的尝试创建了一个简单的示例表。
create tablea (estado char(1), fl_previa_laudo char(1));
我的触发器是这样的:
create trigger ATUALIZA_PREVIA_AI for TABLEA
active after update position 0
as
begin
if( old.estado in ('3', '4', '7', '8') ) then
new.fl_previa_laudo = 'T';
else
new.fl_previa_laudo = 'F';
end;
当我运行触发器时,它给出了一个错误:
can't format message 13:849 -- message file C:\Windows\firebird.msg not found. attempted update of read-only column.
最佳答案
您正在尝试修改 AFTER UPDATE
触发器中的列,但这是不可能的。如果要修改值,则需要使用 BEFORE UPDATE
触发器。参见Firebird documentation on triggers ,具体来说(强调我的):
The
NEW
andOLD
variables are subject to some rules:
- In all triggers, the
OLD
value is read-only- In
BEFORE UPDATE
andBEFORE INSERT
code, theNEW
value is read/write, unless it is aCOMPUTED BY
column- In
INSERT
triggers, references to theOLD
variables are invalid and will throw an exception- In
DELETE
triggers, references to theNEW
variables are invalid and will throw an exception- In all
AFTER
trigger code, theNEW
variables are read-only
换句话说,before update
触发器允许您在持久化行之前修改值,而 after update
触发器在行持久化后触发,从而允许您可以看到最终的值。
关于sql - 尝试更新 AFTER UPDATE 触发器上的只读列错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47905203/