简体   繁体   English

PL / SQL触发器和多次更新

[英]PL/SQL Trigger and multiple updates

I've written a Trigger that only allows an update to a products price if it is at least 10% above cost. 我编写了一个触发器,该触发器仅在价格高于成本至少10%时才允许更新产品价格。 It appears to be working when I update one products price, however I need it to be able to update multiple products at once. 当我更新一个产品的价格时,它似乎正在工作,但是我需要它能够一次更新多个产品。 Any suggestions? 有什么建议么? Thanks to anyone who can help. 感谢任何能提供帮助的人。

create or replace TRIGGER P_check
BEFORE UPDATE ON ProductCat
FOR EACH ROW
BEGIN
IF (:new.ListPrice < :old.TotalCost * 1.1) THEN
 raise_application_error (-20500, :new.ListPrice || ' is too low so the price stays '  ||:old.ListPrice);
 ELSE
 dbms_output.put_line ('Price was updated and the new price is ' || :new.ListPrice);
 END IF;
END;

It should work fine. 它应该工作正常。 You have the trigger defined as FOR EACH ROW ; 您已将触发器定义为FOR EACH ROW thus, your trigger will be invoked for each row changed in ProductCat . 因此,将为ProductCat更改的每一行调用触发器。

Share and enjoy. 分享并享受。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM