Par*_*vez 0 sql oracle triggers plsql
create or replace trigger t1
before update of price on book
declare
vdif number;
begin
vdif:=:new.price-:old.price;
dbms_output.put_line('Price Diff is '||vdif);
end;
Run Code Online (Sandbox Code Playgroud)
我收到这个错误:
表级触发器中不允许使用新引用或旧引用
正如错误消息所示,您无法在表级触发器中使用:new或:old.您需要行级触发器.所以你需要添加FOR EACH ROW到你的声明中
create or replace trigger t1
before update of price on book
for each row
declare
vdif number;
begin
vdif:=:new.price-:old.price;
dbms_output.put_line('Price Diff is '||vdif);
end;
Run Code Online (Sandbox Code Playgroud)
当然,实际上,你永远不会写一个只写入dbms_output缓冲区的触发器(也不会编写依赖于任何人看到任何内容的生成代码dbms_output).但我认为你是一名学生,而你只是将其作为家庭作业的一部分.