我必须创建一个触发器来添加NoOfCustomers'进入STORE表。如果客户数量大于限制,则会显示错误消息。我收到了错误"错误的绑定变量' NEW.NOOFCUSTOMERS'"当我试图运行触发器时,我似乎找不到原因。
CREATE OR REPLACE TRIGGER NoOfCustomersTrigger
BEFORE INSERT ON STORE
FOR EACH ROW
DECLARE V_CAPACITY SHOPS.LIMIT%TYPE;
BEGIN
SELECT LIMIT INTO V_LIMIT
FROM SHOPS, SERVES
WHERE CUSTID = SERVES.CUSTID AND STORENO = :NEW.STORENO;
IF (:NEW.NOOFCUSTOMERS > V_LIMIT) THEN
RAISE_APPLICATION_ERROR (-20004,'The Number of Customers exceeds the LIMIT');
END IF;
END;
答案 0 :(得分:1)
您的代码中似乎存在一些错误,
V_LIMIT
中使用V_CAPACITY
,因为您在代码中使用v_limit
。column ambiguously defined
错误,列必须引用为TABLE.COLUMN_NAME或TABLE_ALIAS.COLUMN_NAME。 试试这个,
CREATE OR REPLACE
TRIGGER noofcustomerstrigger
BEFORE INSERT ON STORE
FOR EACH ROW
DECLARE v_limit shops.LIMIT%TYPE;
BEGIN
SELECT LIMIT INTO v_limit
FROM shops A, serves b
WHERE A.custid = b.custid AND storeno = :NEW.storeno;
IF (:NEW.noofcustomers > v_limit) THEN
raise_application_error (-20004,'The Number of Customers exceeds the LIMIT');
END IF;
END;