如果价格涨幅超过10%,则此触发器会抛出错误。出于某种原因,我收到了PLS-00103错误。
CREATE OR REPLACE TRIGGER product_price_updt
BEFORE UPDATE ON PRODUCT
FOR EACH ROW
DECLARE
price_error VARCHAR2(100);
BEGIN
IF (:new.price > :old.price * 1.1) THEN raise price_error;
END IF;
EXCEPTION
when price_error then ('Price increase is greater than 10%, update cancelled');
END;
这是我在编译时看到的。
Error(7,78): PLS-00103: Encountered the symbol ")" when expecting one of the following: * & = - + < / > at in is mod remainder not rem <an exponent (**)> <> or != or ~= >= <= <> and or like like2 like4 likec as between || multiset member submultiset
也许我的语法错了,错误是误导。我无法找到问题。
答案 0 :(得分:1)
RAISE必须与EXCEPTION一起使用 - 在这里你使用VARCHAR2参数,这是一个问题。我能看到的另一个是你的异常块中你有一个字符串('价格上涨大于10%,更新已取消')你需要某种函数调用。我建议将你的触发器重写为:
CREATE OR REPLACE TRIGGER product_price_updt
BEFORE UPDATE ON PRODUCT
FOR EACH ROW
DECLARE
price_error EXCEPTION;
BEGIN
IF (:new.price > :old.price * 1.1) THEN
raise price_error;
END IF;
EXCEPTION
when price_error then
DBMS_OUTPUT.PUT_LINE('Price increase is greater than 10%, update cancelled');
END product_price_updt;
分享并享受。